Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Testing/setting the CD autorun option under Win32


How can I test and set the CD autorun option under 32 bit versions of Windows?   

    You can check the 4 byte value in the Windows registry under: Software\Microsoft\Windows\CurrentVersion\Policies\ExplorerNoDriveTypeAutoRun Setting the following bit numbers of the value of this key will cause Windows not to use any auto run capabilities that may be present for the device denoted by the bit number.

    DRIVE_UNKNOWN = bit # 0
    DRIVE_NO_ROOT_DIR = bit # 
    DRIVE_REMOVABLE= Bit # 2
    DRIVE_FIXED = Bit #3
    DRIVE_REMOTE= Bit #4
    DRIVE_CDROM= Bit #5
    DRIVE_RAMDISK= Bit #6
    You can also set this value to test the autorun capability of a program you are developing from a floppy or network drive, by setting the value to boot the autorun program from a floppy disk (DRIVE_REMOVEABLE) or network drive (DRIVE_REMOTE). If the device does not have auto-insert detection capabilities, simply inserting the disk and pressing F-5 from the Windows explorer should cause the autorun program to boot.
    The following example demonstrates the ability to check if the autorun detection of the CD is enabled, and also demonstrates the ability of turning the autorun detection both on and off for the CD.
    Example
    uses
      Registry;
    function IsCdAutoRunOn : bool;
    var
      reg: TRegistry;
      AutoRunSetting : integer;
    begin
      reg := TRegistry.Create;
      reg.RootKey := HKEY_CURRENT_USER;
      reg.OpenKey(
        'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',
                  false);
      reg.ReadBinaryData('NoDriveTypeAutoRun',
                         AutoRunSetting ,
                         sizeof(AutoRunSetting));
      reg.CloseKey;
      reg.free;
      result :=  not ((AutoRunSetting and (  shl 5)) <> 0);
    end;
    procedure SetCdAutoRun(bOn : bool);
    var
      reg: TRegistry;
      AutoRunSetting : integer;
    begin
      reg := TRegistry.Create;
      reg.RootKey := HKEY_CURRENT_USER;
      reg.LazyWrite := false;
      reg.OpenKey(
        'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer',
                  false);
      reg.ReadBinaryData('NoDriveTypeAutoRun',
                         AutoRunSetting ,
                         sizeof(AutoRunSetting));
      if bOn then
        AutoRunSetting := AutoRunSetting and not (  shl 5)
      else
        AutoRunSetting := AutoRunSetting or (  shl 5);
      reg.WriteBinaryData('NoDriveTypeAutoRun',
                          AutoRunSetting ,
                          sizeof(AutoRunSetting));
      reg.CloseKey;
      reg.free;
    end;
    procedure TForm .Button Click(Sender: TObject);
    begin
      if IsCdAutoRunOn then
        ShowMessage('CD AutoRun Is On') else
        ShowMessage('CD AutoRun Is Off');
    end;
    procedure TForm .Button2Click(Sender: TObject);
    begin
      SetCdAutoRun(True);
    end;
    procedure TForm .Button3Click(Sender: TObject);
    begin
      SetCdAutoRun(False);
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use