Sign in to follow this  
Followers 0
Tinywoods

Find the CDROM

20 posts in this topic

#1 ·  Posted (edited)

Id like to make a following script that can execute a program (ex. Start.exe) in a CD-ROM. I tried many scripts that I made, but those scripts did not work. B)

Is there anyone who can help me? :o

1. I have 3 CD-Drives and more than 5 virtual CD-Drives.

2. Virtual CD-Drive letters are not fixed. So I may need to use DriveGetDrive

3. In my drives (HDD&CD-Drives), there are some exe-files which are the same name (ex. Start.exe) that I want to execute from the CD-ROM.

So, I dont want to use FileFind* or something like that.

4. When I execute the program in the CDROM, I have to set the CDROM only; I can not set other CDROMs in CD-Drives.

I want to have a caution message, when I set more than 2 CDROMs in CD-Drives. So I may have to use DriveStatus.

5. I'd like to put the script on my desktop.

Edited by Tinywoods

Share this post


Link to post
Share on other sites



I'd like to make a following script that can execute a program (ex. Start.exe) in a CD-ROM. I tried many scripts that I made, but those scripts did not work. B)

Is there anyone who can help me? :o

1. I have 3 CD-Drives and more than 5 virtual CD-Drives.

2. Virtual CD-Drive letters are not fixed. So I may need to use "DriveGetDrive"

3. In my drives (HDD&CD-Drives), there are some exe-files which are the same name (ex. Start.exe) that I want to execute from the CD-ROM.

So, I don't want to use "FileFind*" or something like that.

4. When I execute the program in the CDROM, I have to set the CDROM only; I can not set other CDROMs in CD-Drives.

I want to have a caution message, when I set more than 2 CDROMs in CD-Drives. So I may have to use "DriveStatus".

5. I'd like to put the script on my desktop.

Just put your program on the desktop. The command for the desktop location (see the Help file) is @DesktopCommonDir for all users, or @DesktopDir for the current user.

You have a varying number of optical drives and the drive letter names are unpredictable. You cannot identify them by a common file name on a fixed location on the optical disc as the same file name is used for different things. I think you have a slight problem!

Maybe you could find and extract the file metadetails such as version number, filesize, etc and uniquely identify them that way - the code snippets are here in the forums - do a search for them. Alternatively look for things that are different rather than the same on each mounted CDROM disc and work backwards from there.

Have you checked out the autorun command for when CD volumes are mounted? It is extensively documented at the Micro$oft site.

Good luck!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Just put your program on the desktop. The command for the desktop location (see the Help file) is @DesktopCommonDir for all users, or @DesktopDir for the current user.

You have a varying number of optical drives and the drive letter names are unpredictable. You cannot identify them by a common file name on a fixed location on the optical disc as the same file name is used for different things. I think you have a slight problem!

Maybe you could find and extract the file metadetails such as version number, filesize, etc and uniquely identify them that way - the code snippets are here in the forums - do a search for them. Alternatively look for things that are different rather than the same on each mounted CDROM disc and work backwards from there.

Have you checked out the autorun command for when CD volumes are mounted? It is extensively documented at the Micro$oft site.

Good luck!

Thank you for your interest in my thread. Basically, I have the exact same exe-files in different drives. So, the file version, file sizes are always same.

In details, I intend to execute WPI.hta for Apps installing. Pls refer the site if you don't mind. http://www.wpiw.net/

I have 4 WPI ISO images, and I intend to perform semi-automatic installing for my 4 machines via network. It should not an autorun DVD.

I have to put only one DVD (or ISO image) in my drive when I perform semi-auto install. If I set more than 2 DVDs(or images), I always get in trouble. Therefore, I want to have a caution (Messages) when I make a mistake.

and difine the DVD which I want to excute.

Edited by Tinywoods

Share this post


Link to post
Share on other sites

Is there any idea? B)

Share this post


Link to post
Share on other sites

Is there any idea? B)

Well what about looking for a specific Volume Label (CD Label) across all your drive and running the EXE for that specific label?

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Yes, it is one of solutions, but the CDROM-drive label is not fixed.

Share this post


Link to post
Share on other sites

Yes, it is one of solutions, but the CDROM-drive label is not fixed.

I'm not talking about the CDROM drive, im talking about the actual CD. Everytime you burn a CD it has to have a label.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

I have some drive functions posted here in scripts'n'scraps. They work by label or filename recognition.

Share this post


Link to post
Share on other sites

@blademonkey

Sorry, I misunderstood.

@MHz

Thank you. It works. Then I need to add a script to check numbers of CD.

; Example use
; e.g. _FindCD('Setup.exe', 0) or _FindCD('CD Title', 1)
; $option: 0 = Filename in CD Root; 
; $option: 1 = CD title
$file = "\WPI\WPI.hta"
$result = _FindCD($file, 0)
MsgBox(0, "", $result)

Func _FindCD($name, $option)

    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            $allocated = $drives[$i]
                            Return $allocated
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc
 
$target = $result & $file
MsgBox(0, "", $target)

FileCreateShortcut ( $target, "C:\WPI\WPIHTA.lnk")
run(@comspec & " /c start C:\WPI\WPIHTA.lnk")

Share this post


Link to post
Share on other sites

Another problem has happen.

I made a script that is able to check how many "WPI.hta" files in drives. I tried to combine my script with MHz's script. Each file works alone but it dosen't work when combine into one script.

Code A MHz's script

; Example use
; e.g. _FindCD('Setup.exe', 0) or _FindCD('CD Title', 1)
; $option: 0 = Filename in CD Root; 
; $option: 1 = CD title
$file = "\WPI\WPI.hta"
$result = _FindCD($file, 0)
MsgBox(0, "Drive", $result)

Func _FindCD($name, $option)

    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            $allocated = $drives[$i]
                            Return $allocated
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc
 
$target = $result & $file
MsgBox(0, "Path", $target)

Code B My script (Check number of the files)

; Check the file if there is one or more than one files

$search = FileExists($target) 
$count = 0
; Check if the search was successful
If $search = 0 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While   $count = 0
    $search = 1 
    $count = $count + 1
        If $count >= 2 Then
        $cancel = MsgBox(4096, "Warning", "There are " & $Count & "files in DVDs. Check your DVD-Drives.")
    If $cancel = 1 Then EXIT
    EndIf
Wend

Code C (Execute "WPI.hta") It should be set at the end of combined script

; Execute WPI.hta       
If $count = 1 Then
FileCreateShortcut ( $target, "C:\WPI\WPIHTA.lnk", 1)
Run(@comspec & " /c start C:\WPI\WPIHTA.lnk")
EndIf

Do you have any idea to combine above 3 scrips?

Share this post


Link to post
Share on other sites

I am not sure of understanding your Code B script. You have mentioned multiple WPIs on multiple cdroms so I modified the function to return an array of matched drive letters if the optional parameter is used.

; Example use
; e.g.  _FindCD('Setup.exe', 0, 1);Find all setup.exe in all cdroms and return an array of matches
;       _FindCD('Setup.exe')    ;Find 1st instance of Setup.exe in a cdrom
;       _FindCD('CD Title', 1)  ;Find cdrom title

; $option: 0 = Filename in CD Root (default)
; $array: 1 = Return array of matched drive letters. 

; $option: 1 = CD title

$file = '\WPI\WPI.hta'
$result = _FindCD($file, 0, 1)
For $i = 1 To $result[0]
    MsgBox(0, '', $result[$i])
Next

Func _FindCD($name, $option = 0, $array = 0)
    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            If $array = 1 Then
                                $allocated = $allocated & $drives[$i] & '|'
                                ConsoleWrite($allocated & @LF)
                            Else
                                Return $allocated
                            EndIf
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If $option = 0 And $array = 1 Then
                If StringRight($allocated, 1) = '|' Then
                    $allocated = StringTrimRight($allocated, 1)
                EndIf
                If $allocated Then Return StringSplit($allocated, '|')
            EndIf
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc

Perhaps that maybe more suitable for your needs.

Share this post


Link to post
Share on other sites

Sorry, I'm not good at making script and writing English.

I just want to add a script that can check whether plural WPI.ISO images (or DVDs) are setting or not . Because I have 5 different images (including DVD) for my PCs. Sometimes I've left images in CD drives by mistake. In this case, I fail in Apps installing via a WPI image.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ok, I understand some more. The default FindCD function will find the 1st cdrom that matches. So you could use just the 1st drive for testing to make it easy for your self, else you would have to do file check by created time stamp possibly to resolve on which was your latest cd created or some other means. The latter function would return an array and if $result[0] is larger then 1 then you could use a messagebox as warning that more then one match exists, but to resume with the 1st match or to choose is by more code.

Using the last function couild be like this for checking multiple drive and using the first if desired:

If $result[0] > 1 Then
    If MsgBox(4, 'Warning', 'You have ' & _
        $result[0] & ' WPIs in the cdroms' & _
        @LF & 'Do you want to continue') = 7 Then
        Exit
    EndIf
EndIf

$result[1] = $the_first_match_found

Then use your latter code to run WPI.

Edited by MHz

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Well, this is a rough non-gui solution perhaps:

Global $cddrive = ''
If $result[0] > 1 Then
;; Choose to continue
    If MsgBox(4, 'Warning', 'You have ' & _
        $result[0] & ' WPIs in the cdroms' & _
        @LF & 'Do you want to continue') = 7 Then
        Exit
        For $i = 1 To $result[0]
;        ; Select from multiple drives
            If MsgBox(4, 'Select cdrom', $result[$i]) = 6 Then
                $cddrive = $result[$i]
                ExitLoop
            EndIf
        Next
    EndIf
Else
;; If only 1 drive is found then assigned it a letter
    If $result[0] = 1 Then $cddrive = $result[1]
EndIf
; If no match then Exit
If $cddrive = '' Then Exit
; $cddrive stores your drive letter for useage
$cddrive = $your_selection

$cddrive will hold you selection.

Edit: Updated code.

Edited by MHz

Share this post


Link to post
Share on other sites

Thank you very much B) MHz.

Your script works well !

My question is

;; Choose to continue
    If MsgBox(4, 'Warning', 'You have ' & _
        $result[0] & ' WPIs in the cdroms' & _
        @LF & 'Do you want to continue') = 7 Then
        Exit
        For $i = 1 To $result[0]
;      ; Select from multiple drives
            If MsgBox(4, 'Select cdrom', $result[$i]) = 6 Then
                $cddrive = $result[$i]
                ExitLoop
            EndIf

Though I click "continue", nothing has happen without exit. I can not reach "Select from multiple drives" part.

Could you check this point again? I like your script and I really want to use it with my WPI images.

Share this post


Link to post
Share on other sites

Sure I can help. Sorry, forgot to add an Else after the Exit

Global $cddrive = ''
If $result[0] > 1 Then
; Choose to continue
    If MsgBox(4+262144, 'Warning', 'You have ' & _
        $result[0] & ' WPIs in the cdroms' & _
        @LF & 'Do you want to continue') = 7 Then
        Exit
    Else
        For $i = 1 To $result[0]
        ; Select from multiple drives
            If MsgBox(4+262144, 'Select cdrom', $result[$i]) = 6 Then
                $cddrive = $result[$i]
                ExitLoop
            EndIf
        Next
    EndIf
Else
; If only 1 drive is found then assigned it a letter
    If $result[0] = 1 Then $cddrive = $result[1]
EndIf
    
; If no match then Exit
If $cddrive = '' Then Exit

; $cddrive stores your drive letter for useage
$cddrive = $your_selection

I prepopulated the arrays and seems ok now.

Test arrays

Dim $result[3]
$result[0] = 2
$result[1] = 'c:'
$result[2] = 'd:'

Share this post


Link to post
Share on other sites

Wutsup MHz and Tinywoods!! B)

Share this post


Link to post
Share on other sites

Hello

B) MHz,

Thank you very much ! It works well. Perfect !!

The final version for WPI is as follows,

; Example use
; e.g.  _FindCD('Setup.exe', 0, 1);Find all setup.exe in all cdroms and return an array of matches
;       _FindCD('Setup.exe')   ;Find 1st instance of Setup.exe in a cdrom
;       _FindCD('CD Title', 1)   ;Find cdrom title

; $option: 0 = Filename in CD Root (default)
; $array: 1 = Return array of matched drive letters. 

; $option: 1 = CD title

$file = '\WPI\WPI.hta'
$result = _FindCD($file, 0, 1)
For $i = 1 To $result[0]
    MsgBox(0, '', $result[$i])
Next

Func _FindCD($name, $option = 0, $array = 0)
    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            If $array = 1 Then
                                $allocated = $allocated & $drives[$i] & '|'
                                ConsoleWrite($allocated & @LF)
                            Else
                                Return $allocated
                            EndIf
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If $option = 0 And $array = 1 Then
                If StringRight($allocated, 1) = '|' Then
                    $allocated = StringTrimRight($allocated, 1)
                EndIf
                If $allocated Then Return StringSplit($allocated, '|')
            EndIf
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc

Global $cddrive = ''
If $result[0] > 1 Then
; Choose to continue
    If MsgBox(4+262144, 'Warning', 'You have ' & _
        $result[0] & ' WPIs in the cdroms' & _
        @LF & 'Do you want to continue') = 7 Then
        Exit
    Else
        For $i = 1 To $result[0]
       ; Select from multiple drives
            If MsgBox(4+262144, 'Select cdrom', $result[$i]) = 6 Then
                $cddrive = $result[$i]
                ExitLoop
            EndIf
        Next
    EndIf
Else
; If only 1 drive is found then assigned it a letter
    If $result[0] = 1 Then $cddrive = $result[1]
EndIf
    
; If no match then Exit
If $cddrive = '' Then Exit

; $cddrive stores your drive letter for useage
; $cddrive = $your_selection; delete left(;) if you need

; Execute WPI.hta
$target = $cddrive & $file
 MsgBox(0, '', $target)
   If Not FileExists("C:\WPI\") Then
   DirCreate("C:\WPI\")
   Sleep(2000)
   EndIf
FileCreateShortcut($target, "C:\WPI\WPIHTA.lnk")
Sleep(2000)
Run(@comspec & " /c start C:\WPI\WPIHTA.lnk")

I canceled "$your_selection " part.

Why don't you post this scrip in the WPI forum? It very useful information for a guy who want to execute WPI.hta from DVD.

Hi, totoymola !

I'm happy because I got great support from MHz. Is he your friend?

I just started to use AUTOIT from B's record installation, as you may remember. But it's still difficult for me to make complicated scripts.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I canceled "$your_selection " part.

Why don't you post this scrip in the WPI forum? It very useful information for a guy who want to execute WPI.hta from DVD.

$your_selection was just for poor show for output of $cddrive.

My code is freely available on request. Alot of people seem to have their own methods already for WPI.

I removed ConsoleWrite($allocated & @LF) as that was left in from testing the function.

I also removed

For $i = 1 To $result[0]
    MsgBox(0, '', $result[$i])
Next

as I do not see the point of having so many messageboxes. The other If block should be enough.

The MsgBox(0, '', $target) near the end is your testing messagebox I would assume? I will let you decide on that.

The paths to WPI folder are hardcoded. You could use the @HomeDrive macro?

I grouped your code together at the top of the script for easier reading amd added Exit to simply display the end of script.

; Example FindCD function use
; _FindCD('Setup.exe', 0, 1);Find all setup.exe in all cdroms and return an array of matches
; _FindCD('Setup.exe')    ;Find 1st instance of Setup.exe in a cdrom
; _FindCD('CD Title', 1);Find cdrom title

; $option: 0 = Filename in CD Root (default)
; $array: 1 = Return array of matched drive letters. 

; $option: 1 = CD title

$file = '\WPI\WPI.hta'
$result = _FindCD($file, 0, 1)
$cddrive = ''

If $result[0] > 1 Then
; Choose to continue
    If MsgBox(4 + 262144, 'Warning', 'You have ' & _
            $result[0] & ' WPIs in the cdroms' & _
            @LF & 'Do you want to continue') = 7 Then
        Exit
    Else
        For $i = 1 To $result[0]
        ; Select from multiple drives
            If MsgBox(4 + 262144, 'Select cdrom', $result[$i]) = 6 Then
                $cddrive = $result[$i]
                ExitLoop
            EndIf
        Next
    EndIf
Else
; If only 1 drive is found then assigned it a letter
    If $result[0] = 1 Then $cddrive = $result[1]
EndIf

; If no match then Exit
If $cddrive = '' Then Exit

; $cddrive stores your drive letter for useage

; Execute WPI.hta
$target = $cddrive & $file
MsgBox(0, '', $target)
If Not FileExists("C:\WPI\") Then
    DirCreate("C:\WPI\")
    Sleep(2000)
EndIf
FileCreateShortcut($target, "C:\WPI\WPIHTA.lnk")
Sleep(2000)
Run(@ComSpec & " /c start C:\WPI\WPIHTA.lnk")

Exit

Func _FindCD($name, $option = 0, $array = 0)
    Local $allocated, $drives
    While Not $allocated
        $drives = DriveGetDrive('CDROM')
        If Not @error Then
            For $i = 1 To $drives[0]
                If DriveStatus($drives[$i] & '\') = 'READY' Then
                    If $option = 0 Then
                        If FileExists($drives[$i] & '\' & $name) Then
                            If $array = 1 Then
                                $allocated = $allocated & $drives[$i] & '|'
                            Else
                                Return $allocated
                            EndIf
                        EndIf
                    ElseIf $option = 1 Then
                        $allocated = $drives[$i]
                        If DriveGetLabel($allocated) = $name Then
                            Return $allocated
                        EndIf
                    EndIf
                EndIf
            Next
            If $option = 0 And $array = 1 Then
                If StringRight($allocated, 1) = '|' Then
                    $allocated = StringTrimRight($allocated, 1)
                EndIf
                If $allocated Then Return StringSplit($allocated, '|')
            EndIf
            If Not $allocated Then
                If MsgBox(5 + 16, 'Warning', 'Please insert CD into a drive now') = 2 Then
                    Sleep(1000)
                    If MsgBox(4 + 32, 'Important', 'Are you sure that you want to exit') = 6 Then Exit
                EndIf
                Sleep(2000)
            EndIf
        EndIf
    WEnd
EndFunc

Happy WPI.

Hi, totoymola ! You do get around. B)

Edit: Removed $your_selection line that was still in the code

Edited by MHz

Share this post


Link to post
Share on other sites

Wonderful ! B)

Thank you, I will use above script without any modification.

Share this post


Link to post
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
Sign in to follow this  
Followers 0