简体   繁体   English

如何刷新 Windows 资源管理器

[英]How to refresh Windows Explorer

在此处输入图像描述

A network volume's name can be changed.可以更改网络卷的名称。
I changed the name to Spinal Disk我将名称更改为Spinal Disk
在此处输入图像描述

在此处输入图像描述

To change a network name, I do要更改网络名称,我会

  • Write new name in Registry.在注册表中写入新名称。
  • Attach my network volume using functions like DefineDosDeviceW.使用 DefineDosDeviceW 等函数附加我的网络卷。 In this timing, Windows explorer read registry in my guessing.在这个时候,Windows 资源管理器在我的猜测中读取了注册表。
  • SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, root, NULL); SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, root, NULL); // To be sure. // 为了确定。
  • SendMessageTimeout(HWND_BROADCAST, WM_DEVICECHANGE, message, (LPARAM)(&dbv), - SMTO_ABORTIFHUNG, 200, &dwResult); SendMessageTimeout(HWND_BROADCAST, WM_DEVICECHANGE, message, (LPARAM)(&dbv), - SMTO_ABORTIFHUNG, 200, &dwResult); // To be sure again! // 再次确定!

It works, but sometimes doesn't work even though I use SHChangeNotify and WM_DEVICECHANGE to be sure.它有效,但有时即使我使用 SHChangeNotify 和 WM_DEVICECHANGE 来确定也不起作用。 Sometimes, the new name is not applied in Windows Explorer.有时,新名称不会在 Windows 资源管理器中应用。
But if I terminate Explorer and re-execute, the name applied.但是,如果我终止资源管理器并重新执行,则会应用该名称。

I'm finding an interface having Windows Explorer refreshed.(Is it correct syntax? Sorry, I can't express this sentence well.) I'm finding an interface had Windows Explorer refreshed.(语法正确吗?对不起,我不能很好地表达这句话。)
Is there a proper function?有合适的功能吗? Explorer should re-read registry and be refreshed. Explorer 应该重新读取注册表并刷新。

Unfortunately, Explorer simply can't refresh every time it is told so.不幸的是,Explorer 根本无法在每次被告知时刷新。 Because way too many apps behave badly and always use SHChangeNotify() with SHCNE_ALLEVENTS .因为太多的应用程序表现不佳,并且总是将SHChangeNotify()SHCNE_ALLEVENTS一起使用。 Imagine if the explorer would really always refreshed everything every time it receives that notification (yes, sometimes several times per second.).想象一下,如果资源管理器每次收到该通知时真的总是刷新所有内容(是的,有时每秒刷新几次。)。 That's why it sometimes doesn't work.这就是为什么它有时不起作用的原因。

But here's how you can 'trick' the explorer:但这里是你如何“欺骗”探险家的方法:
Send a notification for more than one path, from the bottom up.从下往上为多个路径发送通知。 Usually it's enough to first send a notification for eg N:\folder and then for N:\ to really refresh N:\ .通常首先发送一个通知就足够了,例如N:\folder然后N:\真正刷新N:\

And you should send the WM_DEVICECHANGE message first , and only then call SHChangeNotify() .您应该发送WM_DEVICECHANGE消息,然后才调用SHChangeNotify()

Use SHChangeNotify().使用 SHChangeNotify()。 Not actually sure which wEventId you'd use in this particular case.实际上不确定在这种特殊情况下您会使用哪个 wEventId。 Start with SHCNE_ALLEVENTS.从 SHCNE_ALLEVENTS 开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM