Does anyone know how to enable or disable programmatically the "Quick Edit Mode" in PowerShell or CMD console ?
I would like to lauch PowerShell from a script (batch) and to give the same look and behavior as the default PowerShell console lauched from the shortcut.
For anybody still looking for a solution, this will disable Quick Edit in the current PowerShell window (tested for windows 10):
Add-Type -MemberDefinition #"
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetStdHandle(int handle);
"# -Namespace Win32 -Name NativeMethods
$Handle = [Win32.NativeMethods]::GetStdHandle(-10)
return [Win32.NativeMethods]::SetConsoleMode($Handle, 0x0080)
Per this script the first call gets the current STDIN, and per this script the second call invokes the SetConsoleMode API with the right value.
Try to set/create a QuickEdit DWord value with value of 1 under the following regkey:
HKEY_CURRENT_USER\Console\<look for powershell related key>
Already answered here, update "QuickMode" setting in Windows Registry:
reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
However it will not affect currently opened window. But you can reopen a window:
:: Get QuickEdit Mode setting from Windows Registry
FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKCU\Console" /v QuickEdit`) DO (
set quickEditSetting=%%A %%B
)
if %quickEditSetting% == 0x0 (
:: Disable QuickEdit Mode
reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
:: Open script in a new Command Prompt window
start "" "%~dpnx0" %* && exit
)
... script logic here ...
exit
Additional info about HKEY_CURRENT_USER\Console Registry configuration - https://renenyffenegger.ch/notes/Windows/registry/tree/HKEY_CURRENT_USER/console/index
Related
How do you write a script to change a registry key? What I am trying to do is have a script I can run to unlock the reading pane in outlook 2016.
The path of the registry key is:
Computer\HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\options
disablereadingpane REG_DWORD 0x00000001 (1)
And I need to change the 1 to a 0. In the 0x00000001
Any help getting started with this would be greatly appreciated.
My comment was faulty it's add not edit.
reg.exe is the command line registry manipulation tool. See reg.exe /?
You may first check if the key exists and what value / data it has.
Reg Query "HKCU\Software\Policies\Microsoft\office\16.0\outlook\options"
To adda key/value/data pair
Reg add "HKCU\Software\Policies\Microsoft\office\16.0\outlook\options" /v disablereadingpane /t REG_DWORD /d 0x0
optionally you may add a /f force option to overwrte current content.
I think you're looking for something like this, if you're using powershell. It's pretty self explanatory
Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\office\16.0\outlook\options -Name disablereadingpane -Value 0
I am trying to create a batch file that will run and open a Powershell script to then run.
this is what i have so far
#echo off
for /r C:\folder %%a in (*) do if "%%~nxa"=="2WNRN4VMS2.txt" set p=%%~dpnxa
if defined p (
echo %p%
) else (
echo File not found
Pause
)
Powershell.exe -Command "& '%p%'"
exit
That is very simple using command DIR for searching for the file recursively in folder C:\folder and all its subfolders and command FOR for assigning the drive and path of found file to an environment variable:
#echo off
for /F "delims=" %%I in ('dir /A-D /B /S "C:\folder\2WNRN4VMS2.txt" 2^>nul') do set "FilePath=%%~dpI" & goto FoundFile
echo File not found
pause
goto :EOF
:FoundFile
Powershell.exe -Command "& '%FilePath%'"
Please note that the string assigned to environment variable FilePath ends with a backslash. Use in PowerShell command line %FilePath:~0,-1% if the path of the file should be passed without a backslash at end.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
dir /?
echo /?
for /?
goto /?
pause /?
set /?
I'm trying to automate printer installation on windows 7 x64, by using Powershell script. So far I have a script that successfully creates TCP/IP port but gives me an error - The arguments are invalid, when it executes printer installation part of the code. Any ideas on how to fix the problem and successfully install a printer through the Powershell? The code is as follows:
$hostAddress = "172.16.2.24"
$portNumber = "9100"
$computer = $env:COMPUTERNAME
$wmi= [wmiclass]"\\$computer\root\cimv2:win32_tcpipPrinterPort"
#$wmi.psbase.scope.options.enablePrivileges = $true
$newPort = $wmi.createInstance()
$newPort.hostAddress = $hostAddress
$newPort.name = "IP_" + $hostAddress
$newPort.portNumber = $portNumber
$newPort.SNMPEnabled = $false
$newPort.Protocol = 1
$newPort.put()
CMD.EXE /C "printui.exe /if /b "Test Printer" /f C:\inetpub\wwwroot\ftp\Prdrivers\HP Universal Print Driver\pcl6-x64-5.7.0.16448\hpbuio100l.inf /r "IP_172.16.2.24" /m "HP Laser Jet P3015""
Question Update: This is the working CMD code, so how do I incorporate it into the Powershell code above ?
printui.exe /if /b "HP Universal Printing PCL 6" /f "C:\inetpub\wwwroot\ftp\Prdrivers\HP Universal Print Driver\pcl6-x64-5.7.0.16448\hpbuio100l.inf" /u /r "IP_172.16.2.24" /m "HP Universal Printing PCL 6"
To embed double-quotes within a double-quoted string you need to escape them. Since you are not using variables, it is easier to use a single quoted string e.g.:
CMD.EXE /C 'printui.exe /if /b "Test Printer" /f C:\inetpub\wwwroot\ftp\Prdrivers\HP Universal Print Driver\pcl6-x64-5.7.0.16448\hpbuio100l.inf /r "IP_172.16.2.24" /m "HP Laser Jet P3015"'
If you ever need to use PowerShell variables inside this string, then you will need to switch back to double quotes and escape the necessary DQ characters e.g:
CMD.EXE /C "printui.exe /if /b `"$PrinterName`" /f C:\inetpub\wwwroot\ftp\Prdrivers\HP Universal Print Driver\pcl6-x64-5.7.0.16448\hpbuio100l.inf /r `"IP_172.16.2.24`" /m `"HP Laser Jet P3015`""
Sorry, but im not sure why you are calling CMD /C #PARAMS. I am just calling the printui.exe directly and it is working, and I only double quote the Args
# Printer Info, I keep this in an SQL DB, and return these values with a query:
$printerID = "<PrinterNameOrID>"
$printerIP = "<PrinterIP>"
$printerPort = "IP_$printerIP"
$printerModel = "<PrinterModelFromINF>"
$driverINFPath = "<UNCPathToDriverINF>"
# Build a new Local TCP Printer Port, naming it with values unique to the Printer ID:
$newPort = ([wmiclass]"Win32_TcpIpPrinterPort").CreateInstance()
$newPort.HostAddress = $printerIP
$newPort.Name = $printerPort
$newPort.PortNumber = "9100"
$newPort.Protocol = 1
$newPort.Put()
# Add the printer
printui.exe /if /b "$printerID" /f "$driverINFPath" /u /r "$printerPort" /m "$printerModel"
I know this has already been answered but you could borrow the code I have in this Excel Workbook (there is a link in the article). I realize it uses VBS but these are built in scripts in Windows and cutting / pasting into Excel has saved me many times and I've installed thousands of printers this way
best-tool-for-printer-creation-excel-vs-print-management-console
Try this:
runas /user:Contoso.com\user1 "printui.exe /if /b \"Test Printer\" /f \"C:\inetpub\wwwroot\ftp\Prdrivers\HP Universal Print Driver\pcl6-x64-5.7.0.16448\hpbuio100l.inf\" /r \"IP_172.16.2.24\" /m \"HP Laser Jet P3015\""
I spend most of my time on command line ( XP / 7 ) and always find myself customizing the command prompt according to my preferences. This applies to both cmd and powershell prompt.
Width: 140
Height: 40
Left: -4
Top: 20
Font: Lucida Console
Font Size: 16
Text Color: RGB(100,150,200)
QuickEdit Mode: Enabled
Whenever I am on a new server, I would need to do this all over again. How can I automate this process by putting these parameters in a batch file or PowerShell script?
You can look into making calls to update the Windows registry.
For example,
REG.EXE add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f
will set QuickEdit as the default mode for your command prompt.
It's easy to slap this line into a batch file, along with other settings.
add Keyname will chose the Key name where to add the value, here HKEY_CURRENT_USER\Console
/v is followed by the name of the value to add
/t followed by its type
/d is followed by the data with which to set the name of the value
/f to force write in the registry without prompt
Likewise, you can modify WindowSize which contains 0xhhhhwwww where the first four bytes is the value of the height in hexa (e.g. 0x003E for a height of 62 pixels) and www is the window's width. For your case:
REG.EXE add HKCU\Console /v WindowSize /t REG_DWORD /d 0x0028008c /f
Type REG /? and REG add /? for more options.
You can use the Registry provider in PowerShell along with the *-Item and *-ItemProperty cmdlets to modify the registry values under this registry key: HKEY_CURRENT_USER\Console.
I'm looking for a way to configure a few options in Folder Option dialog of Windows Explorer through Powershell.
The options are:
Choose "Show hidden files, folders, and drives"
Uncheck "Hide extensions for known file types"
Uncheck "Hide protected operating system files (Recommended)"
Keith's answer didn't work for me out of the box. The only thing that took to the registry value modification was ShowSuperHidden. Both the Hidden (Show hidden files...) and HideFileExt (hide file extension) reverted back to their previous values as soon as I opened the View tab in Folder Settings.
Here's my solution, which I found after some trial and error (explorer.exe is automatically restarted):
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key Hidden 1
Set-ItemProperty $key HideFileExt 0
Set-ItemProperty $key ShowSuperHidden 1
Stop-Process -processname explorer
I tested this on Windows Server 2008 R2 and Windows 7.
sample windows registry (article) script:
Windows Registry Editor Version 5.00
[hkey_current_user\software\microsoft\windows\currentversion\explorer\advanced]
;hide empty drives [uncheck]
"hidedriveswithnomedia"=dword:00000000
;hide extensions for known file types [uncheck]
"hidefileext"=dword:00000000
;show hidden files, folders, and drives [check]
"showsuperhidden"=dword:00000001
;hide folder merge conflicts [uncheck]
"hidemergeconflicts"=dword:00000000
;hide protected operating system files (recommended) [uncheck]
"hidden"=dword:00000001
;use check boxes to select items [check]
"autocheckselect"=dword:00000001
save as *.reg file, and import by clicking on it and confirming the action, or through issuing the reg /import (examples) command on file.
ps: no explorer or system restart required
I believe these correspond to registry entries under reg key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced. You can use the Set-ItemProperty cmdlet to change their value e.g.:
$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key ShowSuperHidden 1
There also seems to be a corresponding key for local machine (as opposed to the per user setting above): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder.
The above registry patches are correct, but they don't fix the entire problem. Here's the script I use. It loops through ALL the users in the registry and the profiles directory (including DEFAULT, so newly-created users get them too) and sets these options for them all.
REM Changes to HKLM are not user-specific
REM Turns "hide file extensions" OFF and "show hidden files" ON.
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt /v DefaultValue /t REG_DWORD /d 0 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL /v DefaultValue /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v Hidden /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t REG_DWORD /d 1 /f
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v DontPrettyPath /t REG_DWORD /d 1 /f
REM Get path to "Users" dir.
echo WScript.Echo CreateObject("WScript.Shell").RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\ProfilesDirectory") >%temp%\profpath.vbs
for /f "tokens=*" %%i in ('cscript //nologo %temp%\profpath.vbs') do set ProfPath=%%i
del /q %temp%\profpath.vbs
REM Modifies registry keys in for all logged in users
REM Also modify it in the .DEFAULT hive so future users get it.
REM Also edits the registry hive for users who are not logged in
REM This section Copyright Jared Barneck
REM Modified by Ken Carlilep0 and Sam Hills
FOR /F "tokens=2* delims=\" %%a IN ('REG QUERY HKU ^|Findstr /R "DEFAULT S-1-5-[0-9]*-[0-9-]*$"') DO CALL :modkey %%a
For /d %%b in ("%ProfPath%\*") do call :modlokey "%%b"
#REM Exiting here ends the whole batch file.
EXIT /B 0
REM Modify logged-out users
:modlokey
set RegFile=%~1\ntuser.dat
REG LOAD HKU\TempHive "%RegFile%">NUL 2>&1
call :modkey TempHive
REG UNLOAD HKU\TempHive >NUL 2>&1
EXIT /B 0
REM Modifications to HKEY_USERS go here:
:modkey
REM Turns "hide file extensions" OFF and "show hidden files" ON.
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "HideFileExt" /t REG_DWORD /d "0" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "Hidden" /t REG_DWORD /d "1" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "ShowSuperHidden" /t REG_DWORD /d "1" /f
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "DontPrettyPath" /t REG_DWORD /d "1" /f
REM Combine taskbar buttons only when taskbar is full
REM 0 = Always combine, hide labels, 1 = Combine when taskbar is full, 2 = Never combine
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "TaskbarGlomLevel" /t REG_DWORD /d "1" /f
REM Enable this line if you use multiple monitors:
REM REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "MMTaskbarGlomLevel" /t REG_DWORD /d "1" /f
REM Don't add "- Shortcut" to new shortcuts
REG ADD "HKU\%1\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "link" /t REG_BINARY /d 00000000 /f
REM Turns on "Computer" Desktop Icon
REG ADD HKU\%1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d 0 /f
REG ADD HKU\%1\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" /t REG_DWORD /d 0 /f
#REM Exiting here only ends this instance of the call to the
#REM :modkey label. It does not end the whole batch file.
EXIT /B 0
Updating this with a bit more info, using Powershell on Windows 10 (v1703-1809) I was able to reference and set the Folder options registry keys for both Current User and Local machine, with the following code.
The biggest realization for me, not obvious in previous posts, was that the reg key paths for folder-options-related settings are subtly different depending on whether you want to get/set Local Machine or Current User, both in key path consistency and key value access. Also, if not obvious, Current User settings will override Local Machine.
Here is a example code snippet (tested w/ PS 5.1):
## Grab Current User setting(s):
$CUfvHidden = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name 'Hidden').Hidden
$CUfvHideFileExt = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name 'HideFileExt').HideFileExt
$CUfvFullPath = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState -Name 'FullPath').FullPath
if ($CUfvHidden -eq 1) { Write-host "CU: Show Hidden set to 'ON'" } #expecting val 1 or 2
else { Write-host "CU: Show Hidden set to 'OFF'" }
if (-not $CUfvHideFileExt) { Write-host "CU: File extensions DISPLAYED" } #expecting val 1 or 0
else { Write-host "CU: File extensions hidden" }
if ($CUfvFullPath) { Write-host "CU: SHOW full path in title bar" } #expecting val 1 or 0
else { Write-host "CU: DO NOT show full path in title bar" }
## Grab Local Machine setting(s)...As you can see the LM reference paths are
## slightly different, to get 1 and 0 values, compared to CU and each other:
$LMfvHidden = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\ShowAll).CheckedValue
$LMfvHideFileExt = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\HideFileExt).CheckedValue
$LMfvFullPath = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\ShowFullPath).CheckedValue
if ($LMfvHidden) { Write-host "LM: Show Hidden set to 'ON'" } #expecting val 1 or 2
else { Write-host "LM: Show Hidden set to 'OFF'" }
if (-not $LMfvHideFileExt) { Write-host "LM: File extensions DISPLAYED" } #expecting val 1 or 0
else { Write-host "LM: File extensions hidden" }
if ($LMfvFullPath) { Write-host "LM: SHOW full path in title bar" } #expecting val 1 or 0
else { Write-host "LM: DO NOT show full path in title bar" }