Configure Windows Explorer Folder Options through Powershell

荒凉一梦 提交于 2019-11-28 04:20:17
guyarad

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.

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.

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 or system restart required

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!