WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Disable CD Autorun


Question:

While running my script I need to disable CD Autorun. I use the registry RegSetDword(@REGMACHINE, "SYSTEM\CurrentControlSet\Services\Cdrom[Autorun]", 0) to disable autorun. This requires system reboot to take effective. Is there any shortcut to avoid reboot, may be through InternalControl? Or any other way to do it by script automatically, like monitoring autorun process and kill the process immediately?

Answer:

You might see if there's a way to do it via WMI. Another idea is to try using the NT extender's service management functions to simply try to stop & restart the cdrom service. It's a device driver, yes, but device drivers are nothing more than a special type of service. I know the autorun setting is read at the time the service starts, so cycling the cdrom device driver service just might get the results that you're looking for.

User Reply:

Thanks for the information. I tried to stop/ start the cdrom service, but it doesn't accept it. I used NET STOP to stop the service. Could you please explain me how to stop and start device driver services? I have never done it before.

Answer:

Using the Registry to Disable AutoRun There are two registry values that can be used to persistently disable AutoRun: NoDriveAutoRun and NoDriveTypeAutoRun. The first value disables AutoRun for specified drive letters and the second disables AutoRun for a class of drives. If either of these values is set to disable AutoRun for a particular device, it will be disabled.

Note The NoDriveAutoRun and NoDriveTypeAutoRun values should only be modified by system administrators to change the value for the entire system for testing or administrative purposes. Applications should not modify these values, as there is no way to reliably restore them to their original values. The NoDriveAutoRun value disables AutoRun for specified drive letters. It is a REG_DWORD data value, found under the following key:

HKEY_CURRENT_USER
Software
Microsoft
Windows
CurrentVersion
Policies
Explorer
The first bit of the value corresponds to drive A:, the second to B:, and so on. To disable AutoRun for one or more drive letters, set the corresponding bits. For example, to disable the A: and C: drives, set NoDriveAutoRun to 0x00000005.

The NoDriveTypeAutoRun value disables AutoRun for a class of drives. It is a REG_DWORD or 4-byte REG_BINARY data value, found under the same key.

HKEY_CURRENT_USER
Software
Microsoft
Windows
CurrentVersion
Policies
Explorer
By setting the bits of this value's first byte, different drives can be excluded from working with AutoRun.

The following table gives the bits and bitmask constants, that can be set in the first byte of NoDriveTypeAutoRun to disable AutoRun for a particular drive type. For Microsoft Windows NT and later systems, you must restart Windows Explorer before the changes take effect.

Bit Number Bitmask Constant Description

0x04 DRIVE_REMOVEABLE Disk can be removed from drive (such as a floppy disk). 
0x08 DRIVE_FIXED Disk cannot be removed from drive (a hard disk). 
0x10 DRIVE_REMOTE Network drive. 
0x20 DRIVE_CDROM CD-ROM drive. 
0x40 DRIVE_RAMDISK RAM disk. 

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

Apply the command line "secedit /refreshpolicy machine_policy /enforce"


Article ID:   W16995
File Created: 2007:07:03:14:27:32
Last Updated: 2007:07:03:14:27:32