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.
Related
i need help to use these registry to be be scripted over to powershell language. Anyone how can help me?
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Helvetica LT Bold (TrueType)" /t REG_SZ /d HelveticaBold.ttf /f
As I'm quite a beginner in powershell, I've tried to search around here and on the web but can't find any ways to solve it.
I'd like to execute .logopen /u /t /d each time I launch WinDbg - so that a logfile will be created automatically, right from the beginning of each session, without me having to specify it explicitly.
Is there a way to specify a certain command / set of commands to be executed upon WinDbg launch?
You can create a shortcut link or batch file which uses the /c command line parameter:
WinDbg.exe /c ".logopen /t /u /d"
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
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
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" }