[英]Uncheck "Show hidden files" in Folder Options with PowerShell
I'm trying to write a script that turns off Windows Explorer Folder Option "Show hidden files, folders, and drives"我正在尝试编写一个脚本来关闭 Windows Explorer 文件夹选项“显示隐藏的文件、文件夹和驱动器”
I followed along with this thread: Toggle "show hidden files and folders with Powershell我跟着这个线程: 切换“显示隐藏的文件和文件夹 Powershell
The code in the top answer seems to change the registry key, but the actual Folder Option doesn't change.最佳答案中的代码似乎更改了注册表项,但实际的文件夹选项并没有改变。 Hidden files remain visible as well.
隐藏的文件也仍然可见。
Here's my code:这是我的代码:
$Path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced'
Set-ItemProperty -Path $Path -Name Hidden -Value 1
$Shell = New-Object -ComObject Shell.Application
# For each one of the open windows, refresh it.
$Shell.Windows() | ForEach-Object { $_.Refresh() }
I know the registry value is changing because I can check that Hidden is changing with this:我知道注册表值正在更改,因为我可以检查 Hidden 是否正在更改:
Get-ItemProperty -Path $Path -Name Hidden
You may need to restart Explorer.exe to pick up the change.您可能需要重新启动 Explorer.exe 以获取更改。
If you add stop-process -name explorer –force
to the end of your script does it then pick up the change?如果您将
stop-process -name explorer –force
添加到脚本的末尾,它会接受更改吗?
I don't know how to do this in PowerShell, but in VBScript I use this solution I developed.我不知道如何在 PowerShell 中执行此操作,但在 VBScript 中,我使用了我开发的这个解决方案。 The solution works on Windows 10 and 11, and with any language.
该解决方案适用于 Windows 10 和 11,并且可以使用任何语言。
Code:代码:
With CreateObject("WScript.Shell")
.RegWrite "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", 1, "REG_DWORD"
.RegWrite "HKCU\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\Shell\{#}\ExplorerCommandHandler", .RegRead( _
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\Shell\Windows.ShowHiddenFiles\ExplorerCommandHandler"), "REG_SZ"
CreateObject("Shell.Application").Namespace(0).ParseName("Shell:RecycleBinFolder").InvokeVerb("{#}")
.Run("Reg.exe Delete HKCU\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\Shell\{#} /F"), 0, True
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.