目前知道的方法:只有运行时按shift,但不适合我的程序要求。
要不修改注册表,因为需要的是暂时禁用而不是永久禁用。
希望各位高人指点下如何实现,或者有什么系统函数之类的可以实现我所需要的功能。

解决方案 »

  1.   

    那你就 模拟按下 shift 键
      

  2.   

    就是说模拟shift键不适合我程序的要求,因为我的程序会不断的换光盘,要在程序运行时不出现光盘自动运行,那位有好的方法?50分不够再给!!!1
      

  3.   

    呵呵,帮你找到解决方法了: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. 
      

  4.   

    UINT g_uQueryCancelAutoPlay = 0;LRESULT WndProc(HWND hwnd, UINT uMsg,  WPARAM wParam, LPARAM lParam) 

        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;               
            }
        } 
    }
      

  5.   

    原文在:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/autorun/autoplay_reg.asp
      

  6.   

    这个方法我知道,不过这个只能在我的当前程序是运行在最前台时才能收到此消息
    但是一旦到后台就不适用了,MSDN上也有写的:Your application's window must be in the foreground to receive this message.
      

  7.   

    开始->运行->gpedit.msc 摸板管理里可以配置是否启用自动运行的功能.
      

  8.   

    呵呵,那就看看能不能HOOK所有窗口进程,看看能不能控制这个消息假设,没有试过:$
      

  9.   

    1。开始->运行->gpedit.msc 摸板管理里可以配置是否启用自动运行的功能.
    这个不行,和该注册表没什么区别
    2。那就把程序设为前台:这个不行,就是要求后台运行
    3HOOK所有窗口进程??这个怎么做呀,还请指教下
      

  10.   

    http://www.vckbase.com/document/viewdoc/?id=488有关于HOOK原理的一些描述
    http://www.pcdog.com/p/html/2004625/25620042911_1.htm有HOOK的简单示例
    我想你需要的是一个全局消息的HOOK,可能需要做一些尝试,不知能否实现你需要的功能