用于切换“显示隐藏文件、文件夹和驱动器”的 API
Windows API 中是否有一个功能可以在 Windows 资源管理器中切换“显示隐藏的文件、文件夹和驱动器”选项(“工具”>>“文件夹选项...”>>“查看”选项卡)。
我知道一个相关的注册表项,但更改它不会立即生效。关键是:HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/Advanced/Hidden
尝试从 C# 执行此操作,但问题不是特定于语言的。
Is there a function in Windows API to toggle the "Show hidden files, folders and drives" option in Windows Explorer (Tools >> Folder Options... >> View tab).
I know of a related registry key, but changing that would not have immediate effect. The key is: HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/Advanced/Hidden
Trying to do this from C#, but the question is not language-specific.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试此线程中的选项 建议,即:
或者
或
这些
不在 .NET C# API 中,因此您必须使用
DllImport
编辑:格式化
You could try the options the OP in this thread suggests, that is:
Either
or
or
These are not in the .NET C# API, so you'll have to use
DllImport
Edit: formatting
除了我在原始问题中添加的评论之外 - 如果您这样做是为了让您要弹出的 OpenFileDialog 显示这些文件 - 不要这样做。
在这种情况下,您最好 P/Invoking GetOpenFileName,并且设置适当的选项(OFN_FORCESHOWHIDDEN(请参阅相关主题的枚举)在 OpenFileName 的标志中 结构,
这样您就只会在适当的时间影响您的应用程序。
In addition to the comment I've added to the original question - if you're doing this so that, for instance, the OpenFileDialog you're about to pop open shows these files - don't do it.
In that case, you're better P/Invoking GetOpenFileName, and setting the appropriate option (OFN_FORCESHOWHIDDEN (see enum for a related subject) in the flags of the OpenFileName structure.
That way you're only affecting your application, at the appropriate time
我知道没有 API,但注册表项是
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden
。从实验来看,值 1 表示显示,值 2 表示隐藏。I know of no API, but the registry key is
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden
. From experimentation, it seems a value of 1 means show and a value of 2 means hide.SHGetSetSettings
SHELLSTATE 结构
f显示所有对象
布尔值
TRUE 则显示所有对象,包括隐藏的文件和文件夹。 FALSE 隐藏隐藏的文件和文件夹。
fShowSysFiles
布尔值
TRUE 表示显示系统文件,FALSE 表示隐藏它们。
Spy++ 表示 WM_SETTINGCHANGE 已发送到资源管理器窗口。
SHGetSetSettings
SHELLSTATE Structure
fShowAllObjects
BOOL
TRUE to show all objects, including hidden files and folders. FALSE to hide hidden files and folders.
fShowSysFiles
BOOL
TRUE to show system files, FALSE to hide them.
Spy++ says a WM_SETTINGCHANGE is sent to the explorer windows.