呵呵,帮你找到解决方法了:Users can manually suppress AutoRun by holding down the SHIFT key when they insert the CD-ROM. However, it is usually preferable to handle this operation programmatically rather than depending on the user. With systems that have Shell version 4.70 and later, Microsoft® Windows® sends a "QueryCancelAutoPlay" message to the foreground window. Your application can respond to this message to suppress AutoRun. This approach is used by system utilities such as the Open common dialog box to disable AutoRun. You will not get a "QueryCancelAutoPlay" message with versions of Windows 95 that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed. The following code fragments illustrate how to set up and handle this message. Your application must be running in the foreground window. First, register "QueryCancelAutoPlay" as a Windows message: uMessage = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
Your application's window must be in the foreground to receive this message. The message handler should return TRUE to cancel AutoRun and FALSE to enable it. The following code fragment illustrates how to use this message to disable AutoRun.
If your application is using a dialog box and needs to respond to a "QueryCancelAutoPlay" message, it cannot simply return TRUE or FALSE. Instead, call SetWindowLong with nIndex set to DWL_MSGRESULT. Set the dwNewLong parameter to TRUE to cancel AutoRun, and FALSE to enable it. For example, the following sample dialog box procedure cancels AutoRun when it receives a "QueryCancelAutoPlay" message. Hide ExampleUINT g_uQueryCancelAutoPlay = 0;BOOL DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { ... default: if (!g_uQueryCancelAutoPlay) { g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay")); } if (uMsg == g_uQueryCancelAutoPlay) { SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); return 1; } } }
Your application's window must be in the foreground to receive this message. The message handler should return TRUE to cancel AutoRun and FALSE to enable it. The following code fragment illustrates how to use this message to disable AutoRun.
{
switch (uMsg)
{
...
default:
if (!g_uQueryCancelAutoPlay)
{
g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
}
if (uMsg && uMsg == g_uQueryCancelAutoPlay)
{
return TRUE; // cancel auto-play
}
}
}
If your application is using a dialog box and needs to respond to a "QueryCancelAutoPlay" message, it cannot simply return TRUE or FALSE. Instead, call SetWindowLong with nIndex set to DWL_MSGRESULT. Set the dwNewLong parameter to TRUE to cancel AutoRun, and FALSE to enable it. For example, the following sample dialog box procedure cancels AutoRun when it receives a "QueryCancelAutoPlay" message. Hide ExampleUINT g_uQueryCancelAutoPlay = 0;BOOL DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
...
default:
if (!g_uQueryCancelAutoPlay)
{
g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
}
if (uMsg == g_uQueryCancelAutoPlay)
{
SetWindowLong(hDlg, DWL_MSGRESULT, TRUE);
return 1;
}
}
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/autorun/autoplay_reg.asp
但是一旦到后台就不适用了,MSDN上也有写的:Your application's window must be in the foreground to receive this message.
这个不行,和该注册表没什么区别
2。那就把程序设为前台:这个不行,就是要求后台运行
3HOOK所有窗口进程??这个怎么做呀,还请指教下
http://www.pcdog.com/p/html/2004625/25620042911_1.htm有HOOK的简单示例
我想你需要的是一个全局消息的HOOK,可能需要做一些尝试,不知能否实现你需要的功能