awannaknow
Joined: 14 Jun 2009 Posts: 324
|
Posted: Sat Jan 30, 2010 4:08 pm Post subject: How to run a file from a cd rom on Pc w/more than 1 cd rom ? |
|
|
Whatta found :
2 solutions, the first I found is ok and working but not the best, if you have to use it, use the second.
Here they are, I start with the second because this is the one to use:
| Code: | DriveGet, cddrives, list, cdrom
Loop, parse, cddrives
IfExist, %drive%:\Autorun.exe
Run, %A_LoopField%:\Autorun.exe, , Hide UseErrorLevel |
Now the First solution I found :
| Code: |
DriveGet, cddrives, list, cdrom
StringSplit, CdDrivesArray, cddrives
Loop, %CdDrivesArray0%
drive := CdDrivesArray%a_index%
IfExist, %drive%:\Autorun.exe
Run, %drive%:\Autorun.exe, , Hide
|
Explanation about who do what at ahk home :
| Code: | ;-------------------------------------
;DriveGet
;Retrieves various types of information about the computer's drive(s).
;DriveGet, OutputVar, Cmd [, Value]
;------------------------------------
;StringSplit
;Separates a string into an array of substrings using the specified delimiters.
;StringSplit, OutputArray, InputVar [, Delimiters, OmitChars]
;------------------------------------
;Loop (normal)
;Perform a series of commands repeatedly: either the specified number of times or until break is encountered.
;Loop [, Count]
;------------------------------------
;Loop (parse a string)
;Retrieves substrings (fields) from a string, one at a time.
;Loop, Parse, InputVar [, Delimiters, OmitChars]
;------------------------------------
;Run / RunWait
;Runs an external program. Unlike Run, RunWait will wait until the program finishes before continuing.
;Run, Target [, WorkingDir, Max|Min|Hide|UseErrorLevel, OutputVarPID]
;------------------------------------
;IfExist / IfNotExist
;Checks for the existence of a file or folder.
;IfExist, FilePattern
;IfNotExist, FilePattern
;AttributeString := FileExist(FilePattern)
;------------------------------------
|
Time to find a solution : it tooks me 3 days of hard reading, hard banging my head against the walls, jumping around until exhausted, drinking a lot, yieling, shouting, etc...
If you too have a solution, don't hesitate to add to this thread.
---------------------------------------------
---------------------------------------------
Shortest :
Hi Everybody,
I need a hint on this :
If I want to start an install program from a cd rom, friendly ahk can say for me :
| Code: | | Run, N:\Autorun.exe ; N is the CD Rom drive letter and Autorun.exe the file I want to run |
But if there is more than 1 cd rom, I didn't find how to do it ? :
A bit longer :
I spent a lot of time reading the forum to find examples, what I found I tried to adapt but failed.
From now the best I've done was to modify a script up to this :
| Code: | ;DriveGet
;Retrieves various types of information about the computer's drive(s).
;DriveGet, OutputVar, Cmd [, Value]
DriveGet, cddrives, list, cdrom
if (cddrives = "") { ;If the OutputVar is empty (means: no cd rom)
msgbox, No cdroms found ;open a message box that says No cdroms found
ExitApp ; stop the script here
}
;/*
if StrLen(cddrives) > 1 { ; If there is more than 1 character in the OutputVar (means if there is more than one cd rom)
;Loop (parse a string)
;Retrieves substrings (fields) from a string, one at a time.
;Loop, Parse, InputVar [, Delimiters, OmitChars]
loop, parse, cddrives
{
if (A_Index != 1) ; If the number of loop is different from 1 (means if there is more than 1 cd rom)
;Var := expression
;Evaluates an expression and stores the result in a variable.
;Var := expression
sep := " or "
choices .= sep """" A_loopField """" ;The built-in variable A_LoopField exists within any parsing loop. It contains the contents of the current substring (field) from InputVar
}
InputBox, cdrom, Choose a drive, More than one cdrom was found.`nEnter the drive letter to use: %choices%
,,,,,,,, % SubStr(cddrives,1,1) ;SubStr(String, StartingPos [, Length]) [v1.0.46+]: Copies a substring from String starting at StartingPos and proceeding rightward to include at most Length characters (if Length is omitted, it defaults to "all characters").
}
;*/
else cdrom := cddrives
msgbox, Press OK to do "Run %cdrom%:\Autorun.exe"
Run %cdrom%:\Autorun.exe
ExitApp |
I may add that I seached the forum and ahk help file to try to understand the script, but did not understand everything, for example like this part :
| Code: | sep := " or " ; and this what will the expression do ...?
choices .= sep """" A_loopField """" ;no idea about what is .= nor the meaning of the entire line. I found what is A_loopField , but that's all...
|
Now, the expression cddrives hold only one string : the user input from the InputBox
| Code: | | else cdrom := cddrives |
but I don't understand how, althought I don't need to know how to solve my problem it's just out of curiosity, just because awannaknow .
I have to find a way either to :
1- try to launch Autorun.exe from the first cd, then the next , etc..., up until it works
or,
2 - Search on the 1rst cd rom for the file then the next, etc ..., and when the file is found, launch it.
3- Some other way I have not thought of ?
Thanks for reading.
-----------------------------------
-----------------------------------
To ahk :
I love you ahk,
would you marry me ?
----------------------------------
----------------------------------
To readers (secretely) :
So, I could ask :
"How to code this, how to code that, can you code this for me while I fix eveything else"
---------------------------------
---------------------------------
* For those who wonder, I said drinking and as a programmer is to be to the accurate I must accure : drinking, yes, but drinking coffe, . . .

Last edited by awannaknow on Sat Jan 30, 2010 10:31 pm; edited 5 times in total |
|