通过Powershell配置Windows资源管理器文件夹选项

时间:2010-12-20 17:08:10

标签: powershell registry windows-explorer

我正在寻找一种通过Powershell在Windows资源管理器的“文件夹选项”对话框中配置几个选项的方法。

选项包括:

  • 选择“显示隐藏的文件,文件夹和驱动器”
  • 取消选中“隐藏已知文件类型的扩展程序”
  • 取消选中“隐藏受保护的操作系统文件(推荐)”

5 个答案:

答案 0 :(得分:53)

基思的回答对我来说不起作用。修改注册表值的唯一方法是ShowSuperHidden。一旦我在“文件夹设置”中打开“视图”选项卡,“隐藏(显示隐藏文件...)”和“隐藏文件扩展名”(隐藏文件扩展名)都会恢复为之前的值。

这是我的解决方案,我在一些试验和错误(explorer.exe自动重启)后找到了:

$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

我在Windows Server 2008 R2和Windows 7上对此进行了测试。

答案 1 :(得分:7)

我认为这些对应于reg key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced下的注册表项。您可以使用Set-ItemProperty cmdlet更改其值,例如:

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key ShowSuperHidden 1

本地计算机似乎也有相应的密钥(与上面的每个用户设置相对):HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder

答案 2 :(得分:5)

示例windows registry (article)脚本:

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

保存为*.reg文件,然后通过单击并确认操作或通过在文件上发出reg /import (examples)命令进行导入。

ps:无或需要重新启动系统

答案 3 :(得分:0)

上面的注册表补丁是正确的,但是它们不能解决整个问题。这是我使用的脚本。它将遍历注册表和个人档案目录中的所有用户(包括DEFAULT,因此新创建的用户也可以获取它们),并为他们全部设置这些选项。

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

答案 4 :(得分:0)

使用 Windows 10 (v1703-1809) 上的 Powershell 更新更多信息,我能够使用以下代码引用和设置当前用户和本地计算机的文件夹选项注册表项。

对我来说最大的认识,在以前的帖子中并不明显,是文件夹选项相关设置的注册表键路径根据您是否要获取/设置而略有不同本地机器或当前用户,无论是键路径一致性还是键值访问。此外,如果不明显,当前用户设置将覆盖本地计算机。

这是一个示例代码片段(使用 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" }