5

enter image description here

A network volume's name can be changed.
I changed the name to Spinal Disk
enter image description here

enter image description here

To change a network name, I do

  • Write new name in Registry.
  • Attach my network volume using functions like DefineDosDeviceW. In this timing, Windows explorer read registry in my guessing.
  • SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, root, NULL); // To be sure.
  • 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. Sometimes, the new name is not applied in Windows Explorer.
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.)
Is there a proper function? Explorer should re-read registry and be refreshed.

1
  • Benjamin, did you find a solution to your problem in the meantime? I'm having a related problem (not the same), but I think if you've found a solution it could help me as well. Could you please describe your result?
    – CodeX
    Commented Aug 14, 2015 at 11:02

2 Answers 2

4

Unfortunately, Explorer simply can't refresh every time it is told so. Because way too many apps behave badly and always use SHChangeNotify() with 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 e.g. N:\folder and then for N:\ to really refresh N:\.

And you should send the WM_DEVICECHANGE message first, and only then call SHChangeNotify().

1
  • 1
    Thanks. It makes a sense. Please explain it to me little more. Why should I send the WM_DEVICECHANGE message first? Is there a reason? Actually, I don't know what it does internally. I saw the code at TrueCrypt opensource project. They sent WM_DEVICECHANGE last. And why do you think it works well if I send notification N:/folder then N:/? Before trying them, I'd like to understand that. Btw, you are the developer of tortoisesvn! I love it. Glad to see you.
    – Benjamin
    Commented Feb 11, 2011 at 6:47
3

Use SHChangeNotify(). Not actually sure which wEventId you'd use in this particular case. Start with SHCNE_ALLEVENTS.

2
  • Try drive remove + drive add. Commented Feb 9, 2011 at 2:16
  • It might work well. But I don't even know whether the new name has been applied well or not, after attach my network volume. So I can not try remove and re-add.
    – Benjamin
    Commented Feb 9, 2011 at 2:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.