Hello all,

Those of you who read this list on a regular basis may have come across
and remembered my previous posts where I was trying to figure out how to
do proper drive letter assignments via the Mount Manager in my disk
driver. Well, this seems to be no longer a question.

What I'm stuck with now is how to make Explorer refresh its My Computer
view so the newly created drive becomes visible there.

The MSDN states that the DefineDosDevice() function will create a
symbolic link and then send an appropriate WM_SETTINGCHANGE message to
all the interested parties. This has proven to work.

The problem is I have been creating the link via the Mount Manager and,
therefore, all that's left now is doing a proper notification.

Given that, I have tried different ways to notify the user space apps,
namely Explorer. But none of them has ever worked. Below comes a little
code snippet I was trying to use. I would really appreciate any ideas or
links to some sample code that does the notification.

== 8< == the code snippet goes below == 8< ==

printf("Sending notify... \n");
DWORD_PTR ret;
SendMessageTimeout(HWND_BROADCAST,
WM_SETTINGCHANGE,
0L,
(LPARAM) "SYSTEM\\MountedDevices",
SMTO_ABORTIFHUNG,
5000,
&ret);
printf("Done.\n");

printf("Second try...\n");
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
printf("Done.\n");

printf("third try...\n");
LPITEMIDLIST pidlMyComputer = NULL;
SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlMyComputer);
SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, pidlMyComputer, 0L);
printf("Done.\n");

printf("Fourth try...\n");
DEV_BROADCAST_VOLUME hdr;
hdr.dbcv_devicetype = DBT_DEVTYP_VOLUME;
hdr.dbcv_flags &= DBTF_MEDIA;
hdr.dbcv_unitmask = 0xffffffff;
SendMessageTimeout(HWND_BROADCAST,
WM_DEVICECHANGE,
DBT_DEVICEARRIVAL,
(LPARAM)&hdr,
SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG,
5000,
&ret
);
printf("Done.\n");

printf("Fifth try...\n");
BroadcastSystemMessage(BSF_FORCEIFHUNG |
BSF_IGNORECURRENTTASK |
BSF_NOTIMEOUTIFNOTHUNG,
BSM_ALLCOMPONENTS,
WM_DEVICECHANGE,
DBT_DEVICEARRIVAL,
(LPARAM)&hdr
);
printf("Done.\n");

printf("Sixth try...\n");
BroadcastSystemMessage(BSF_FORCEIFHUNG |
BSF_IGNORECURRENTTASK |
BSF_NOTIMEOUTIFNOTHUNG,
BSM_ALLCOMPONENTS,
WM_SETTINGCHANGE,
NULL,
NULL
);
printf("Done.\n");

== 8< == the code snippet ends here == 8< ==

I guess the first thing that comes to mind is that I may have created my
device objects or symlinks somehow wrong, but a simple restart of
Explorer shows the drive in the My Computer view... so therefore, I
guess, the device objects and symlinks are created okay. The
notification doesn't work though. :-/

--
Andrey Subbotin
ICQ UIN: 114087545
LiveJournal: http://www.livejournal.com/users/e_ploko/

Re: WM_SETTINGCHANGE and Explorer by Sergei

Sergei
Mon Sep 12 11:33:05 CDT 2005

For similar purpose I use combination of:

BroadcastSystemMessage(BSF_POSTMESSAGE|BSF_FORCEIFHUNG, NULL,
WM_DEVICECHANGE, DBT_DEVICEARRIVAL, <DEV_BROADCAST_VOLUME* here>);

and

SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, <LPTSTR with drive path
here>, NULL);

Thus no WM_SETTINGCHANGE. So far it works fine. (Although my driver does not
use Mount Manager,
but I don't think it would make difference.)


"Andrey Subbotin" <eploko@gmail.com> wrote in message
news:uC0IT%23utFHA.2568@TK2MSFTNGP15.phx.gbl...
> Hello all,
>
> Those of you who read this list on a regular basis may have come across
> and remembered my previous posts where I was trying to figure out how to
> do proper drive letter assignments via the Mount Manager in my disk
> driver. Well, this seems to be no longer a question.
>
> What I'm stuck with now is how to make Explorer refresh its My Computer
> view so the newly created drive becomes visible there.
>
> The MSDN states that the DefineDosDevice() function will create a
> symbolic link and then send an appropriate WM_SETTINGCHANGE message to
> all the interested parties. This has proven to work.
>
> The problem is I have been creating the link via the Mount Manager and,
> therefore, all that's left now is doing a proper notification.
>
> Given that, I have tried different ways to notify the user space apps,
> namely Explorer. But none of them has ever worked. Below comes a little
> code snippet I was trying to use. I would really appreciate any ideas or
> links to some sample code that does the notification.
>
> == 8< == the code snippet goes below == 8< ==
>
> printf("Sending notify... \n");
> DWORD_PTR ret;
> SendMessageTimeout(HWND_BROADCAST,
> WM_SETTINGCHANGE,
> 0L,
> (LPARAM) "SYSTEM\\MountedDevices",
> SMTO_ABORTIFHUNG,
> 5000,
> &ret);
> printf("Done.\n");
>
> printf("Second try...\n");
> SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
> printf("Done.\n");
>
> printf("third try...\n");
> LPITEMIDLIST pidlMyComputer = NULL;
> SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlMyComputer);
> SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, pidlMyComputer, 0L);
> printf("Done.\n");
>
> printf("Fourth try...\n");
> DEV_BROADCAST_VOLUME hdr;
> hdr.dbcv_devicetype = DBT_DEVTYP_VOLUME;
> hdr.dbcv_flags &= DBTF_MEDIA;
> hdr.dbcv_unitmask = 0xffffffff;
> SendMessageTimeout(HWND_BROADCAST,
> WM_DEVICECHANGE,
> DBT_DEVICEARRIVAL,
> (LPARAM)&hdr,
> SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG,
> 5000,
> &ret
> );
> printf("Done.\n");
>
> printf("Fifth try...\n");
> BroadcastSystemMessage(BSF_FORCEIFHUNG |
> BSF_IGNORECURRENTTASK |
> BSF_NOTIMEOUTIFNOTHUNG,
> BSM_ALLCOMPONENTS,
> WM_DEVICECHANGE,
> DBT_DEVICEARRIVAL,
> (LPARAM)&hdr
> );
> printf("Done.\n");
>
> printf("Sixth try...\n");
> BroadcastSystemMessage(BSF_FORCEIFHUNG |
> BSF_IGNORECURRENTTASK |
> BSF_NOTIMEOUTIFNOTHUNG,
> BSM_ALLCOMPONENTS,
> WM_SETTINGCHANGE,
> NULL,
> NULL
> );
> printf("Done.\n");
>
> == 8< == the code snippet ends here == 8< ==
>
> I guess the first thing that comes to mind is that I may have created my
> device objects or symlinks somehow wrong, but a simple restart of
> Explorer shows the drive in the My Computer view... so therefore, I
> guess, the device objects and symlinks are created okay. The
> notification doesn't work though. :-/
>
> --
> Andrey Subbotin
> ICQ UIN: 114087545
> LiveJournal: http://www.livejournal.com/users/e_ploko/