Jump to content

How to get the Drive letter from CD drive?


Recommended Posts

Hey

Sorry about my language.

I want to auto start a program on a cd, but that program needs to know what drive the cd is in.

I know how to autostart the cd, but I need to pass on the drive letter to the program.

The drive letter will change from Pc to PC.

The command is:

< DevPath.exe X:\ >

The X is the drive letter. Is there a way that AutoIt can catch the drive letter?

Link to comment
Share on other sites

DriveGetDrive("CDROM")


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Then use DriveStatus on the results from DriveGetDrive("CDROM")


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

So if a Pc has 2 cd drives with a cd inserted...then?

Maybe I can check on the cd label.....

That is how I would do it.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

  • Moderators

It's actually quite easy... This will return an array if you want a CD drive that has a CD in it and the label...

Local $EmptyCDDrive = _DriveCD_Available(0)
Local $NotEmptyCDDrive = _DriveCD_Available()
If $EmptyCDDrive Then MsgBox(64, 'Info:', $EmptyCDDrive  & ' is Empty')
If IsArray($NotEmptyCDDrive) Then MsgBox(64, 'Info:', 'The Drive is: ' & $NotEmptyCDDrive[1] & @CR & 'The label is: ' & $NotEmptyCDDrive[2])

Func _DriveCD_Available($iReturnEmpty = 1)
    Local $sDrive = DriveGetDrive('CDROM')
    For $iCount = 1 To $sDrive[0]
        Local $sStatus = DriveStatus($sDrive[$iCount])
        If $sStatus = 'NOTREADY' And Not $iReturnEmpty Then
            Return StringUpper($sDrive[$iCount]) & '\' ; 1 = Empty
        ElseIf $sStatus = 'READY' And $iReturnEmpty Then
            ; 1 = Not Empty / returns an array of [1] =Drive and [2] = Label
            Return StringSplit($sDrive[$iCount] & '\' & Chr(01) & DriveGetLabel(StringUpper($sDrive[$iCount]) & '\'), Chr(01))
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That is how I would do it.

With

$var = DriveGetDrive( "CDROM" ) I get all the cd drives

How can I chek on the array to see what the label?

$var = DriveGetLabel( "c:\" ), I ned to change ( "c:\" ) so it cheks the return from DriveGetDrive....

How?

Link to comment
Share on other sites

  • Moderators

Blah, I just made another one lol with a 2 dim to get all the drives :whistle: Then I read that above!
Local $EmptyCDDrive = _DriveCD_Available(0)
If IsArray($EmptyCDDrive) Then
    For $i = 1 To UBound($EmptyCDDrive) - 1
        MsgBox(64, 'Info:', $EmptyCDDrive[$i][0]  & ' is Empty')
    Next
EndIf

Local $NotEmptyCDDrive = _DriveCD_Available()
If IsArray($NotEmptyCDDrive) Then
    For $i = 1 To UBound($NotEmptyCDDrive) - 1
        MsgBox(64, 'Info:', 'The Drive is: ' & $NotEmptyCDDrive[$i][0] & @CR & 'The label is: ' & $NotEmptyCDDrive[$i][1])
    Next
EndIf

Func _DriveCD_Available($iReturnEmpty = 1)
    Local $sDrive = DriveGetDrive('CDROM'), $iOK
    Local $aStoreInfo, $aLabelInfo
    For $iCount = 1 To $sDrive[0]
        Local $sStatus = DriveStatus($sDrive[$iCount])
        If $sStatus = 'NOTREADY' And Not $iReturnEmpty Then
            $iOK = 1
            $aStoreInfo &= $sDrive[$iCount] & '\' & Chr(01)
        ElseIf $sStatus = 'READY' And $iReturnEmpty Then
            ; 1 = Not Empty / returns an array of [N][0] =Drive and [N][1] = Label
            $iOK = 1
            $aStoreInfo &= $sDrive[$iCount] & '\' & Chr(01)
            $aLabelInfo &= DriveGetLabel($sDrive[$iCount] & '\') & Chr(01)
        EndIf
    Next
    If $iOK Then
        $aStoreInfo = StringSplit(StringTrimRight($aStoreInfo, 1), Chr(01))
        $aLabelInfo = StringSplit(StringTrimRight($aLabelInfo, 1), Chr(01))
        Local $a2DimArray[UBound($aStoreInfo)][2]
        For $iCount = 1 To UBound($aStoreInfo) - 1
            $a2DimArray[$iCount][0] = $aStoreInfo[$iCount]
            If $iReturnEmpty Then 
                $a2DimArray[$iCount][1] = $aLabelInfo[$iCount]
            Else
                $a2DimArray[$iCount][1] = ''
            EndIf
        Next
        Return $a2DimArray
    EndIf
    Return SetError(1, 0, 0)
EndFunc
Ahh well, I'll have a look at yours... probably better than mine anyway.

Edit:

Cleaned the function up a bit.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Sorry if this sounds dumb.

But why dont you just use @WorkingDir.

If the program is running from the cd and you want to access other files on the cd using @WorkingDir will work fine.

Sorry i'm a newbee :whistle:

Link to comment
Share on other sites

  • Moderators

Sorry if this sounds dumb.

But why dont you just use @WorkingDir.

If the program is running from the cd and you want to access other files on the cd using @WorkingDir will work fine.

Sorry i'm a newbee :whistle:

Not a newbish question really :) ... I thought he was starting some other program other than his own from a CD. @ScriptDir would work there as well if he's running from the actual CD.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Sorry i'm a newbee :whistle:

So true partially, JoneZ

If the script in question resides on the CD, then running that script knows it's location through the macro's of @ScriptDir and @ScriptFullPath. Take the first letter for your drive.

A script that resides on the HDD would use a Find CDRom UDF as suggested above.

:)

Link to comment
Share on other sites

Hey

I ended up with this;

Dim $var ;All Cd Drives

Dim $Drive ;Drive letters

Dim $Label ;Drive Label

$var = DriveGetDrive( "CDROM" )

If NOT @error Then

For $i = 1 to $var[0]

$Drive = $var[$i]

$Label = DriveGetLabel( $Drive )

If $Label = "XP_Home_2_0" Then

run devpath.exe $Drive

Endif

Next

EndIf

Edited by knotten2
Link to comment
Share on other sites

Hey

I ended up with this;

Dim $var ;All Cd Drives

Dim $Drive ;Drive letters

Dim $Label ;Drive Label

$var = DriveGetDrive( "CDROM" )

If NOT @error Then

For $i = 1 to $var[0]

$Drive = $var[$i]

$Label = DriveGetLabel( $Drive )

If $Label = "XP_Home_2_0" Then

run devpath.exe $Drive

Endif

Next

EndIf

I am glad that has worked for you. I figured I would link to a Script that I have created in the Scripts and Scraps forum that would possibly help you do this.

_ComputerGet*Info* You would specifically need _ComputerGetDrives.

Below is a sample script to do what you need.

#include "ComputerGetInfo.au3"
Dim $Drives

_ComputerGetDrives($Drives, "CDROM")

For $i = 1 To $Drives[0][0] Step 1
    If $Drives[$i][2] = "XP_Home_2_0" Then
        MsgBox(0, "Drive Letter", $Drive[$i][0])
    EndIf
Next

The above may be way more than what you need, but I thought I would present it as there may be other Computer Information pieces that you may need. I am trying to get an entire set of UDF's setup to cover the information that one may need to glean from a computer.

I hope all goes well for you,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Thank you JS, that explains alot :whistle:

I am glad that has worked for you. I figured I would link to a Script that I have created in the Scripts and Scraps forum that would possibly help you do this.

_ComputerGet*Info* You would specifically need _ComputerGetDrives.

Below is a sample script to do what you need.

#include "ComputerGetInfo.au3"
Dim $Drives

_ComputerGetDrives($Drives, "CDROM")

For $i = 1 To $Drives[0][0] Step 1
    If $Drives[$i][2] = "XP_Home_2_0" Then
        MsgBox(0, "Drive Letter", $Drive[$i][0])
    EndIf
Next
oÝ÷ Ù8ZL¨¸­«^ÆZ{B¢jnµêÆzÒ'~®Ý«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ìÍÉ¥ÁÑ¥½¸èIÑÕɹÌÑ¡É¥Ù¥¹½ÉµÑ¥½¸Í½¸ÀÌØíÍÉ¥ÙQåÁ¥¸Ñݼ(쥵¹Í¥½¹°ÉÉ严ÉÍÐ¥µ¹Í¥½¸¥ÌÑ¡¥¹à½È ÍÐ(ì½É¥Ù¥¹½ÉµÑ¥½¸¸(ìAɵÑȡ̤èÀÌØíÉ¥Ù%¹¼´  äIɹ´É¥Ù¥¹½ÉµÑ¥½¸¥¸¸ÉÉä¸(ìÀÌØíÍÉ¥ÙQåÁ´QåÁ½É¥ÙѼÉÑÕɸѡ¥¹½ÉµÑ¥½¸½¸¸(ì=ÁÑ¥½¹ÌèÅÕ½Ðí10ÅÕ½Ðì°ÅÕ½Ðí
I=4ÅÕ½Ðì°ÅÕ½ÐíI5=Y   1ÅÕ½Ðì°ÅÕ½Ðí%aÅÕ½Ðì°(ìÅÕ½Ðí9Q]=I,ÅÕ½Ðì°ÅÕ½ÐíI5%M,ÅÕ½Ðì°½ÈÅÕ½ÐíU9-9=]8ÅÕ½Ðì(ìÕ±ÑÌѼÅÕ½Ðí%aÅÕ½ÐìÉ¥Ù̸(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤è=¸MÕÍÌ´IÑÕɹÌÉÉä½É¥Ù¥¹½ÉµÑ¥½¸¸(ìÀÌØíÉ¥Ù%¹½lÁulÁtô9յȽɥÙÌ(ìQ¡Í½¹¥µ¹Í¥½¸¥Ì̽±±½ÝÌè ÀÌØí¤ÍÑÉÑÌÐĤ(ìlÀÌØí¥ulÁt´É¥Ù1ÑÑÈ¡à¸èÀäÈì¤(ìlÀÌØí¥ulÅt´¥±MåÍÑ´(ìlÀÌØí¥ulÉt´1°(ìlÀÌØí¥ulÍt´MÉ¥°9ÕµÈ(ìlÀÌØí¥ulÑt´ÉMÁ(ìlÀÌØí¥ulÕt´Q½Ñ°MÁ(ì=¸¥±ÕÉ´IÑÕɸÀ´ÉɽȴÄ(ìáѹèÄôÉ¥ÙÑÉ¥ÙÉɽÈ(ìÈôÉ¥ÙÑ¥±MåÍÑ´ÉɽÈ(ìÌôÉ¥ÙÑ1°ÉɽÈ(ìÐôÉ¥ÙÑMÉ¥°ÉɽÈ(ìÔôÉ¥ÙMÁÉÉɽÈ(ìØôÉ¥ÙMÁQ½Ñ°ÉɽÈ(ìÕÑ¡½È¡Ì¤è)ÉÙ¥ÌMÑÕ±¥±¡ÍÕÁÁ½ÉÐÅÕ½ÐíÐÅÕ½ÐìÙ½ÉÑáÉÙ½±ÕÑ¥½¹ÌÅÕ½Ðí½ÐÅÕ½Ðì½´¤(ì9½Ñ¡Ì¤è(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}
½µÁÕÑÉÑÉ¥ÙÌ¡    åIÀÌØíÉ¥Ù%¹¼°ÀÌØíÍÉ¥ÙQåÁôÅÕ½Ðí%aÅÕ½Ðì¤(1½°ÀÌØíÉ¥Ù(ÀÌØíÉ¥ÙôÉ¥ÙÑÉ¥Ù ÀÌØíÍÉ¥ÙQåÁ¤(%9=PÉɽÈQ¡¸(¥´ÀÌØíÉ¥Ù%¹½mU  ½Õ¹ ÀÌØíÉ¥Ù¥ulÙt(ÀÌØíÉ¥Ù%¹½lÁulÁtôÀÌØíÉ¥ÙlÁt(½ÈÀÌØí¤ôÄQ¼ÀÌØíÉ¥Ù%¹½lÁulÁtMÑÀÄ(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÁtôMÑÉ¥¹UÁÁÈ ÀÌØíÉ¥ÙlÀÌØí¥tµÀìÅÕ½ÐìÀäÈìÅÕ½Ðì¤(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÅtôÉ¥ÙÑ¥±MåÍÑ´ ÀÌØíÉ¥ÙlÀÌØí¥t¤(%ÉɽÈQ¡¸MÑÉÉ½È Ä°È°À¤(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÉtôÉ¥ÙÑ1° ÀÌØíÉ¥ÙlÀÌØí¥t¤(%ÉɽÈQ¡¸MÑÉÉ½È Ä°Ì°À¤(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÍtôÉ¥ÙÑMÉ¥° ÀÌØíÉ¥ÙlÀÌØí¥t¤(%ÉɽÈQ¡¸MÑÉÉ½È Ä°Ð°À¤(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÑtôÉ¥ÙMÁÉ ÀÌØíÉ¥ÙlÀÌØí¥t¤(%ÉɽÈQ¡¸MÑÉÉ½È Ä°Ô°À¤(ÀÌØíÉ¥Ù%¹½lÀÌØí¥ulÕtôÉ¥ÙMÁQ½Ñ° ÀÌØíÉ¥ÙlÀÌØí¥t¤(%ÉɽÈQ¡¸MÑÉÉ½È Ä°Ø°À¤(9áÐ(±Í(MÑÉÉ½È Ä°Ä°À¤(¹%)¹Õ¹í}
½µÁÕÑÉÑÉ¥ÙÌ

The above may be way more than what you need, but I thought I would present it as there may be other Computer Information pieces that you may need. I am trying to get an entire set of UDF's setup to cover the information that one may need to glean from a computer.

I hope all goes well for you,

JS

Link to comment
Share on other sites

Hey JS

Where do I put ComputerGetInfo.au3?

When I run the "small part" I get;

C:\Documents and Settings\Kunde\Skrivebord\ComputerGetInfo.au3(41,44) : ERROR: SetError() [built-in] called with wrong number of args.

If @error Then SetError(1, 2, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I have both fies in the same directory.....

Does it require the beta version?

Edited by knotten2
Link to comment
Share on other sites

Hey JS

Where do I put ComputerGetInfo.au3?

When I run the "small part" I get;

C:\Documents and Settings\Kunde\Skrivebord\ComputerGetInfo.au3(41,44) : ERROR: SetError() [built-in] called with wrong number of args.

If @error Then SetError(1, 2, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

I have both fies in the same directory.....

Does it require the beta version?

Yes I do apologize for not posting that in the post here. It does require Beta. I dont use anything else so I kinda forgot to post it in here. It is in the Computer Info UDF link in my signature, and in the link I posted above.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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...