Hi Jeff,
Thanks for your quickly reply!
Firstly please take a look at the link below.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/shell/programmersguide/shell_basics/shell_basics_extending/autorun/aut
oplay_reg.asp
I understand that you are using the registry approach to disable the
autoplay.
As we know the OS will interactive with Hardware via driver. So but the
Cdrom driver will check the registry key to see if the key is set, if it is
disable, then it will now send notify message. So this behavior is by
design.
But for your scenario, I think you may try another approach to cancel the
autoplay "Suppressing AutoRun Programmatically" in the link above.
Here is some "C#" code which works at my side.
private const int WM_DEVICECHANGE = 0x219;
private const int DBT_DEVICEARRIVAL = 32806;
private const int DBT_DEVICEREMOVECOMPLETE = 32809;
[DllImport("user32.dll", SetLastError = true, CharSet =
CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);
/* only needed if your application is using a dialog box and needs to
* respond to a "QueryCancelAutoPlay" message, it cannot simply return TRUE
or FALSE.
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
*/
//provide a private internal message id
private UInt32 queryCancelAutoPlay = 0;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DEVICECHANGE)
{
Debug.WriteLine("Devide Changed");
}
//calling the base first is important, otherwise the values you
set later will be lost
base.WndProc(ref m);
//if the QueryCancelAutoPlay message id has not been
registered...
if (queryCancelAutoPlay == 0)
queryCancelAutoPlay =
RegisterWindowMessage("QueryCancelAutoPlay");
//if the window message id equals the QueryCancelAutoPlay
message id
if ((UInt32)m.Msg == queryCancelAutoPlay)
{
/* only needed if your application is using a dialog box
and needs to
* respond to a "QueryCancelAutoPlay" message, it cannot
simply return TRUE or FALSE.
SetWindowLong(this.Handle, 0, 1);
*/
m.Result = (IntPtr)1;
Debug.WriteLine("Cancel");
}
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.