Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Powershell配置Windows资源管理器文件夹选项_Powershell_Registry_Windows Explorer_Explorer - Fatal编程技术网

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

通过Powershell配置Windows资源管理器文件夹选项,powershell,registry,windows-explorer,explorer,Powershell,Registry,Windows Explorer,Explorer,我正在寻找通过Powershell在Windows资源管理器的文件夹选项对话框中配置几个选项的方法 这些选择包括: 选择“显示隐藏的文件、文件夹和驱动器” 取消选中“隐藏已知文件类型的扩展名” 取消选中“隐藏受保护的操作系统文件(推荐)” 我相信这些对应于注册表项下的注册表项HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced。您可以使用Set-ItemProperty cmdlet更

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

这些选择包括:

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

我相信这些对应于注册表项下的注册表项
HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
。您可以使用Set-ItemProperty cmdlet更改其值,例如:

$key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty $key ShowSuperHidden 1
本地计算机似乎也有相应的键(与上面的每个用户设置相反):
HKEY\u local\u machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder

对我来说不是现成的。修改注册表值的唯一方法是ShowSuperHidden。在“文件夹设置”中打开“视图”选项卡后,“隐藏”(显示隐藏文件…)和“隐藏文件扩展名”)都恢复为以前的值

这是我的解决方案,经过一些尝试和错误(explorer.exe会自动重新启动)后发现:

$key='HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
设置ItemProperty$key隐藏1
Set-ItemProperty$key HideFileExt 0
Set-ItemProperty$key ShowSuperHidden 1
停止进程-进程名资源管理器
我在Windows Server 2008 R2和Windows 7上对此进行了测试。

示例脚本:

另存为
*.reg
文件,通过单击该文件并确认操作,或通过对文件发出命令来导入


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

上述注册表修补程序是正确的,但它们不能解决整个问题。这是我使用的脚本。它循环遍历注册表和profiles目录中的所有用户(包括默认用户,因此新创建的用户也会获得这些用户),并为所有用户设置这些选项

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

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

我最大的体会是,文件夹选项相关设置的reg密钥路径在密钥路径一致性和密钥值访问方面存在细微差异,这取决于您是要获取/设置本地计算机还是当前用户。此外,如果不明显,当前用户设置将覆盖本地计算机

下面是一个示例代码段(使用PS 5.1测试):


同一类别中的另一个,尽管主题初学者没有特别要求:Set ItemProperty$key TaskbarGlomLevel 2这将禁用任务栏上类似打开的应用程序的分组。这还需要重新启动explorer进程才能应用它。如果用户和本地计算机不一样呢?哪个优先?我试过了,似乎用户设置优先,我们需要更改创建用户配置文件时使用的默认值。它们可能位于不同的注册表位置。可以从powershell命令行运行:reg import file.reg
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
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
## 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" }