Jump to content

Determine if a CD Burner is installed?


Recommended Posts

Hi all,

Anyone know how to use autoit to determine if a CD Burner is installed on a system?

I'm working on a universal Windows Install DVD for when i do repairs, and need such a detection tool so the software pre-install knows whether to install Nero on the system or not. Nero Burning software on a system without a burner is quite useless... :)

I have been able to make a simple script to determine if ANY CD drive is installed (DriveGetDrive and an If statement...), but not just burners.

Anyone know how this could be done? I'm not good with things like COM and WMI, so examples would be much appreciated, especially if you have to use such techniques...

Link to comment
Share on other sites

rajeshontheweb, I tried your UDF, but it doesn't report "Writing" for capabilities on any burner, and i tried two different drives on different systems. I'm not sure what you mean by the "random access", but that shows up even if i'm looking at a NON-burner...Maybe its because i used a virtual PC DVD Drive for my non-burner?

monoceres, that udf doesn't seem to check/report if a drive can burn. When I ran its example on a system without a burner (Virtual PC, i don't have a physical non-burner drive laying around), it tried to burn the folder to a drive that can't burn, and simply hung.

It works as long as that hotfix is installed and I have a burner with media though.

Anyone got any ideas? The burner i am trying it with is a LiteOn LTR-482465. The non-burner is the DVD drive in Virtual PC which is running XP. According to MS, the VPC drive is read-only and can't "burn" to ISO images.

Edited by wolstech
Link to comment
Share on other sites

monoceres, that udf doesn't seem to check/report if a drive can burn. When I ran its example on a system without a burner (Virtual PC, i don't have a physical non-burner drive laying around), it tried to burn the folder to a drive that can't burn, and simply hung.

Sure my UDF can determine if a drive can burn. _IMAPI2_DriveGetSupportedMedia() is the function you're looking for.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

OK, i made progress, but it is thinking that all CD drives are burners.

As per your recommendation, i used _IMAPI2_DriveGetSupportedMedia()

The following is what i tried:

#include "IMAPI2.au3"
#include <Array.au3>

$ids = _IMAPI2_DrivesGetID()
If $ids[0] = 0 Then Exit
For $i = 1 To $ids[0]
    
; Get the object
    $drive = _IMAPI2_DriveGetObj($ids[$i])
    If IsObj($drive) = 0 Then ContinueLoop
    
    $SupportedMedia = _IMAPI2_DriveGetSupportedMedia($drive)
    _ArraySearch($SupportedMedia,$IMAPI_MEDIA_TYPE_CDRW)
    If @error Then 
        MsgBox(0,'debug',_IMAPI2_DriveGetLetter($drive) & ' is not a burner')
    Else
        MsgBox(0,'debug',_IMAPI2_DriveGetLetter($drive) & " is a burner!")
    EndIf
Next
Exit

It is still reporting that a non-burner is capable of burning. On my VPC, it reports the read only drive as being capable of CD-Rs.

Is there a different Media i should be checking for? I used the CD-R constant since 99.9% of burners handle CD-Rs. I checked the media codes being returned with _ArrayDisplay and both burner and non-burner have the same set of codes. Maybe its the VPC drive after all?

Link to comment
Share on other sites

Maybe you can combine what you have with this.

;==============================================================================
; Function Name:   _Drive_Optical_Type()
; Description:   Retrieve the type of drive (CD, DVD, Virtual &etc.)
; Syntax:   _Drive_Optical_Type( $Drive, [$Computer] )
; Parameter(s):   $Drive - The drive to check.  This MUST include the colon (eg. a:
;                          $Computer - The network computer to check (Default is localhost)
; Requirement(s):   WMI capable system
; Return Value(s):   Success - Returns the drive type
; Author(s):   George Gedye (GEOSoft) geog AT mvps DOT org
; Example(s):
#cs
   $Drives = DriveGetDrive("CDROM")
   For $I = 1 To Ubound($Drives) -1
   MsgBox(0, "Test", "Drive " & StringUpper($Drives[$I]) & " is a  " & _Drive_Optical_Type($Drives[$I]))
   Next
#ce
;==============================================================================

Func _Drive_Optical_Type( $Drive, $Computer = ".")
   If DriveGetType($Drive) <> "CDROM" Then Return SetError(1)
   Local $oRtn = "", $sHold = ""
   $Drive = StringUpper($Drive)
   $Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2")
   $Items = $Obj_CD.ExecQuery("Select * from Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39))
   
   For $Item in $Items
      If StringInStr($Item.DeviceID, "virtual") Then $sHold = "Virtual "
      $oRtn = StringRegExpReplace($Item.DeviceID, "(?i)(?m:^).*(cd|dvd[+-]*\w{2}m).+", "$1")
   Next
   If $oRtn = "" Then Return SetError(1)
   Return $sHold & $oRtn
EndFunc  ;<==> _Drive_Optical_Type()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Just an update, I found out one system i have has two CD drives, one thats not a burner. Running the script i posted above on that system made Autoit crash after the first drive's (burner) info.

I tried that func that was given by geosoft, but it just returns "CD" regardless of the burning ability of the drive. Tried on my system with burner, a Virtual PC w/o burner, and a physical system w/o burner.

Has anyone had this much trouble before with this? Every script i've tried seems to claim that my non-burner in VPC is a burner.

EDIT: tried on VPC again and got DVD-ROM this time...

EDIT2: Just noticed on geosoft's function - it says my non-DVD burner drive (it can't even read them!) is capable of DVD-RAM, DVD+R,DVD+RW, DVD+R DL, and DVD-R, DVD-RW, DVD-R DL media...So i think that function just doesn't work...

Edited by wolstech
Link to comment
Share on other sites

The problem he may run into here is the very fact that he wants this for some pre-install work. When using IMAPI2 code, it won't be installed on the system. Remember that IMAPI2 is an optional download patch which also requires that the system be checked. WMI will be installed by default and at that stage it will not have been disabled by anyone.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Just tried rajeshontheweb's second script. It still reports all drives as burners, even on a system w/o which has no burner. I checked the key that is referenced in the UDF, and sure enough, all my CD drives are listed there, including non-burners, so thats a no-go.

I'm quite stumped as to why MS made it so hard to determine if something can burn CDs...

Also, i think that the _IMAPI2_DriveGetSupportedMedia() function is getting the media that the drive can READ, not write. If i view the drive info with Nero's InfoTool, the READable media types listed there for a drive mostly match with the codes the function returns.

InfoTool can create a log file with burning capability info, but go figure that InfoTool can't be controled from the command line (at least from what a quick google says). I can't seem to script it easily either. Even with a log, I have no idea on how to parse it, since its different on every system. I'd say it would cover the bases, if we can make autoit make sense of it. If you want to see what the InfoTool log looks like, i've attached one from my system, with only the relevant parts included. I omitted the OS and other hardware info.

InfoTool.txt

@geosoft - The lack of IMAPI 2 is not a problem, so anything that uses it is welcome. I can include the IMAPI2 package as one of many hotfixes that are applied during Windows Setup, just so its there for this script after the reboot. This tool will run during the first boot to the Windows Desktop, from the "HKLM\software\microsoft\windows\currentversion\RunOnceEx" Key.

Link to comment
Share on other sites

@geosoft - The lack of IMAPI 2 is not a problem, so anything that uses it is welcome. I can include the IMAPI2 package as one of many hotfixes that are applied during Windows Setup, just so its there for this script after the reboot. This tool will run during the first boot to the Windows Desktop, from the "HKLM\software\microsoft\windows\currentversion\RunOnceEx" Key.

Make sure that you have the correct package (there are 2)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Looks like you're not the only one with this problem. There are some possible solutions on this page

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

IMAPI2 Package

This is where i got it. I chose the Windows XP x86, since i'm not on a 64-bit OS. Is that what you mean? I'm pretty sure that the x64 wouldn't install anyway.

Either way, i'm still stumped as to why so many different method don't work for me...IMAPI2 (from the package above) is working for me, since those scripts do run w/o errors. It just gives back incorrect results.

Do I just happen to be unlucky and have 5 different incompatible drives? I have two Lite-on burners of different models (one IDE internal, one USB external), a Dell OEM burner, a Dell OEM NON-burner, and Virtual PCs DVD Drive.

Link to comment
Share on other sites

IMAPI2 Package

This is where i got it. I chose the Windows XP x86, since i'm not on a 64-bit OS. Is that what you mean? I'm pretty sure that the x64 wouldn't install anyway.

Either way, i'm still stumped as to why so many different method don't work for me...IMAPI2 (from the package above) is working for me, since those scripts do run w/o errors. It just gives back incorrect results.

Do I just happen to be unlucky and have 5 different incompatible drives? I have two Lite-on burners of different models (one IDE internal, one USB external), a Dell OEM burner, a Dell OEM NON-burner, and Virtual PCs DVD Drive.

Did you look at the registry solutions in that link I gave you? On a fresh install there shouldn't be a problem. Just use RegRead() and either RegEnumValue() Or RegEnumkey() depending on the setup for those keys. I forget what they were.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Oops, you posted while i was typing. I just looked at the link.

It might just work. I checked the keys for the 5 drives i have, and the EnableImapi's were in the right places, with no non-burners having a 1. I'll throw something together and let you know if i get it working.

Link to comment
Share on other sites

Sweet! Got it working. Like you said, using Regenumkey on those keys made it simple to find out if a burner was installed.

Results:

On a PC with a single burner: Ran preinstall.cmd fine!

On a VPC with a single non-burner: Exited w/o doing anything as expected.

On a PC with a burner drive and a non-burner drive - Ran preinstall.cmd fine!

I used the following (likely poorly written) code. Likely no SATA drive support.

Specify the program to run if a burner is installed at the top. In my case, its a preinstall.cmd that installs Nero 6.

No COM objects, no WMI, no IMAPI2! :)

#cs ----------------------------------------------------------------------------

 Script Function:
    Checks to see if a CD-Burner is present.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#NoTrayIcon

Dim $i, $x
Dim $IDEKey = "HKLM\SYSTEM\CurrentControlSet\Enum\IDE"

Dim $FileToRun = @ScriptDir & "\Preinstall.cmd"
Dim $Arguments = ""
Dim $UseComSpec = 1
Dim $WorkingDir = @ScriptDir

For $i = 1 To 10
    $Subkey1 = RegEnumKey($IDEKey,$i)
    If @error <> 0 Then ExitLoop
    $Subkey1 = $IDEKey & "\" & $Subkey1;Prepend the path to it
    For $x = 1 To 10
        $Subkey2 = RegEnumKey($Subkey1,$x)
        If @error <> 0 Then ExitLoop

        $Subkey2 = $Subkey1 & "\" & $Subkey2
        $IsImapiEnabled = RegRead($Subkey2 & "\Device Parameters\Imapi","EnableImapi")
        If @error <> 0 Then $IsImapiEnabled = 0
        If $IsImapiEnabled = 1 Then
            If $UseComSpec = 1 Then
                RunWait(@ComSpec & ' /c "' & $FileToRun & '" ' & $Arguments,$WorkingDir)
                If @error <> 0 Then MsgBox(16,"Error","Couldn't run " & $FileToRun & " " & $Arguments,10)
            Else
                RunWait($FileToRun & " " & $Arguments,$WorkingDir)
                If @error <> 0 Then MsgBox(16,"Error","Couldn't run " & $FileToRun & " " & $Arguments,10)
            EndIf
            Exit
        EndIf
    Next
Next
Exit

Making a UDF from this likely wouldn't be hard at all.

Any comments on this?

Link to comment
Share on other sites

Looks decent the way it is.

EDIT: Using this method in a UDF may not work. In your case it's fine because you are running a fresh install. If, on the otherhand, it was a system which had been installed for a while, there could be issues with hardware changes that have taken place. When you swap out a drive from a burner to a non-burner (or visa versa) the registry values don't get deleted so it could potentially give erroneous results.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

hmm, it is truly baffling. coz my second udf is supposed to read through registry and ONLY those which are capable of cd writing using the inbuilt windows cd writing wizard are supposed to get in there, in which case it is theoretically not possible for a third party drive which is not supported by windows inbuilt cd wizard also wouldbe excluded. but in your case we see even ROMs are detected, truly strange. i thought i had ended up some place where i could get writable cd info... lets see

and one thing, would u be able to post your CD drives' Name and ID here. so that we can check up if there is anything. because i read somewhere one (not so foolproof) solution which says 'RW' or 'W' in the Drive's caption could be used to identify if it is capable of writing. i know its dumb but it fails only rarely... (even ms website posted similar methodology to detect DVD drive using WMI !!!)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...