Solved

Cancel AutoPlay in Windows (XP and after) with C++

Posted on 2010-08-24
6
790 Views
Last Modified: 2013-11-20
O.S. : Windows XP and up
Language : C++

Hey guys, I am making an application which will be sent out on a multiple DVD set. All the DVDs will have their own autorun.inf file (cannot change this) and once the program is started, it requires different DVDs to be inserted. This poses the unacceptable annoyance of having the autoplay run for each DVD. I know Windows provides a way to cancel this (http://msdn.microsoft.com/en-us/library/cc144204%28VS.85%29.aspx) but I am unsure how to use this (I am not too familiar with C++).

Just copying the first part about registering the windows messages
     uMessage = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
provides a compilation error of missing a type. I am unsure what the type would be, or if I am missing some #include or linked library. Also, the next part of the provided code :

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

does not work with the "..." and undefined "hDlg"

Any suggestions on how to implement this into a project (or other ideas, changing the registry is not exactly my best option, with the ever-present chance of not being able to assure changed the key back)? My apologies for my ineptitude.

Thanks in advance!
0
Comment
Question by:j_willy
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 33512198
http://support.microsoft.com/kb/967715

How to selectively disable specific Autorun features
To selectively disable specific Autorun features, you must change the NoDriveTypeAutoRun entry in one of the following registry key subkeys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\policies\Explorer\

The following table shows the settings for the NoDriveTypeAutoRun registry entry. Collapse this tableExpand this tableValue Meaning
0x1 or 0x80 Disables AutoRun on drives of unknown type  
0x4 Disables AutoRun on removable drives  
0x8 Disables AutoRun on fixed drives  
0x10 Disables AutoRun on network drives  
0x20 Disables AutoRun on CD-ROM drives  
0x40 Disables AutoRun on RAM disks  
0xFF Disables AutoRun on all kinds of drives  
The value of the NoDriveTypeAutoRun registry entry determines which drive or drives the Autorun functionality will be disabled for. For example, if you want to disable Autorun for network drives only, you must set the value of NoDriveTypeAutoRun registry entry to 0x10.

If you want to disable Autorun for multiple drives, you must add the corresponding hexadecimal values to the 0x10 value. For example, if you want to disable Autorun for removable drives and for network drives, you must add 0x4 and 0x10, which is the mathematical addition of 2 hexadecimal values, to determine the value to use. 0x4 + 0x10 = 0x14. Therefore, in this example, you would set the value of the NoDriveTypeAutoRun entry to 0x14.

The default value for the NoDriveTypeAutoRun registry entry varies for different Windows-based operating systems. These default values are listed in the following table. Collapse this tableExpand this tableOperating system Default value
Windows Server 2008 and Windows Vista 0x91
Windows Server 2003 0x95
Windows XP 0x91
Windows 2000 0x95


You don't need c++ for this.  you can batch it to edit the registry, just be sure to change it back to the old setting when done (can be accomplished via an export, then import).
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 33512230
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 33512277
Hi j_willy,

in which kind of application do you need this? With MFC or without? If MFC, a dialog, SDI or MDI?

I.e. if it's for a MFC dialog application it's quite easy. Just add a line like this near the top (but at least below the '#include "stdafx.h"') of the dialog's implementation file:

    UINT g_uQueryCancelAutoPlay = RegisterWindowMessage( TEXT("QueryCancelAutoPlay") );

Then add a message handler for this message by adding a entry to the dialogs message map, i.e. add this somewhere between 'BEGIN_MESSAGE_MAP' and 'END_MESSAGE_MAP':

    ON_REGISTERED_MESSAGE( g_uQueryCancelAutoPlay, OnQueryCancelAutoPlay )

Add a function declararation for this message handler in the dialog class declaration like this:

    afx_msg LONG OnQueryCancelAutoPlay (WPARAM wParam, LPARAM lParam);

and implement it somehow like this in your dialog (here I assume the name of the dialogs class is CTestDlg, replace it with your dialog classes name):

    LONG CTestDlg::OnQueryCancelAutoPlay(WPARAM wParam, LPARAM lParam)
    {
     return 1;
    }


Hope that helps,

ZOPPO
    }




0
Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

 
LVL 31

Expert Comment

by:Zoppo
ID: 33512285
Ahh - sorry - I was too slow ...
0
 
LVL 86

Expert Comment

by:jkr
ID: 33512359
Well, all you have to do is remove the dots and use the appropriate Window handle:
BOOL DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

    switch (uMsg)

    {

    /* ... other code here */

    default:

        if (!g_uQueryCancelAutoPlay)

        {

            g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));

        }

        if (uMsg == g_uQueryCancelAutoPlay)

        {

            SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);          

            return 1;              

        }

    }

}

Open in new window

0
 

Author Comment

by:j_willy
ID: 33513025
Sorry for my delay, was in a meeting.

@Zoppo : I believe that is exactly what I am looking for (It is MFC dialog, MDI). I will test it after my lunch meeting to make sure, then award the points or request some additional info if i hit any snags.

@ged325 : The program I am using is written in C++, so writing another program in C# (as your link appears to suggest) would seem to be more work than required, and again, editing the registry is not my ideal solution as this will be sent out to client computers, and there is no way to guarantee I can return the registry to its original state (ie program/computer crash or something to that extent) but thank you for the suggestion.

@jkr : Thanks for clearing that up.
0

Featured Post

Why won’t your email signature format correctly?

Struggling to get your corporate email signatures to format correctly? Does the logo keep resizing? Is the text appearing too big? What can you do to prevent this? Find out how you can save your signatures today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now