icemanV Posted April 17, 2007 Share Posted April 17, 2007 My intention is to create a folder with all the shortcuts to their batch file. I have created a search for the filename and is able to identify the list of files in the folder. However, the problem is when i try to use the run command to execute the DOS command prompt. I cannot seem to input the shortcuts filename into DOS command prompt. Any idea how I can use the DOS to execute the shortcuts or any other methods? Thanks Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 (edited) Use Start with @ComSpec may suit your need RunWait('"' & @ComSpec & '" /c start path\to\shortcut.lnk', '', @SW_HIDE) Edited April 17, 2007 by MHz Link to comment Share on other sites More sharing options...
icemanV Posted April 17, 2007 Author Share Posted April 17, 2007 Use Start with @ComSpec may suit your need RunWait('"' & @ComSpec & '" /c start path\to\shortcut.lnk', '', @SW_HIDE) The problem is i want the activate the shortcuts by the filename found. Which means I have shortcut A, shortcut B and shortcut C in the folder. I have to click once and it activate shortcut A, shortcut B and shortcut C. Which means RunWait(""& @ComSpec & "/c start path\to" filename', '',@SW_HIDE) filename cannot be hardcoded, it has to be a variable. Somehow, RunWait does not take in the filename. Any idea how i can have a variable in this function RunWait???? Thanks Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 Actually, Start is not needed for shortcuts so the quote issue for title is not a problem without using it. Example with using variables. $a = @ScriptDir & '\test\a.lnk' $b = @ScriptDir & '\test\b.lnk' $c = @ScriptDir & '\test\c.lnk' DirCreate(@ScriptDir & '\test') FileCreateShortcut('explorer.exe', $a) FileCreateShortcut('explorer.exe', $B) FileCreateShortcut('explorer.exe', $c) RunWait('"' & @ComSpec & '" /c "' & $a & '"', '', @SW_HIDE) RunWait('"' & @ComSpec & '" /c "' & $b & '"', '', @SW_HIDE) RunWait('"' & @ComSpec & '" /c "' & $c & '"', '', @SW_HIDE) DirRemove(@ScriptDir & '\test', 1) Link to comment Share on other sites More sharing options...
icemanV Posted April 17, 2007 Author Share Posted April 17, 2007 Actually, Start is not needed for shortcuts so the quote issue for title is not a problem without using it. Example with using variables. $a = @ScriptDir & '\test\a.lnk' $b = @ScriptDir & '\test\b.lnk' $c = @ScriptDir & '\test\c.lnk' DirCreate(@ScriptDir & '\test') FileCreateShortcut('explorer.exe', $a) FileCreateShortcut('explorer.exe', $B) FileCreateShortcut('explorer.exe', $c) RunWait('"' & @ComSpec & '" /c "' & $a & '"', '', @SW_HIDE) RunWait('"' & @ComSpec & '" /c "' & $b & '"', '', @SW_HIDE) RunWait('"' & @ComSpec & '" /c "' & $c & '"', '', @SW_HIDE) DirRemove(@ScriptDir & '\test', 1) Hi I tried to change my code to use your logic but i get this error. RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE) The directory name is invalid. This is my code Dim $filename Dim $exeName Dim $tempScriptName fileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Dim $search = FileFindFirstFile(@WorkingDir & "\*.lnk") While $search = 1 MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) if StringIsAlpha($filename) == 1 Then MsgBox(0, "file1 : ", $filename) ElseIf $filename == "" Then MsgBox(0, "file 2 : ", $filename) Else RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE) EndIf $filename = FileFindNextFile($search) If @error Then ExitLoop WEnd This is just the testing phase for me, hence the if debug statement. Any idea what did i do wrong? i wish they have a book that describe this tool. Thanks Link to comment Share on other sites More sharing options...
SadBunny Posted April 17, 2007 Share Posted April 17, 2007 RunWait('"' & @ComSpec & '" /p"' & $tempScriptName & '""' & '@echo. && pause', @SW_HIDE)The directory name is invalid.It seems you forgot to place a space between the " /p" and the $tempScriptName, leading to /pmyscript instead of /p myscript. Try '" /p "' instead (space between p and quote). Keep this in mind for the rest of the line too, like with the @echo. String concatenations do NOT intrudoce spaces, you have to enter them yourself Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 (edited) Perhaps this is what you want? Global $filename, $exeName, $tempScriptName FileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk") If $search <> -1 Then While 1 $filename = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) If StringIsAlpha($filename) Then MsgBox(0, "file1 : ", $filename) ElseIf $filename = "" Then MsgBox(0, "file2 : ", $filename) Else RunWait('"' & @ComSpec & '" /c "' & $tempScriptName & '"', @SW_HIDE) EndIf WEnd FileClose($search) EndIf If you want to see what @ComSpec is doing then change the @SW_HIDE parameter to @SW_SHOW and use the /k switch instead of /c. Edit: Added FileClose() to close the handle. Edited April 17, 2007 by MHz Link to comment Share on other sites More sharing options...
icemanV Posted April 17, 2007 Author Share Posted April 17, 2007 Perhaps this is what you want? Global $filename, $exeName, $tempScriptName FileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk") If $search <> -1 Then While 1 $filename = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) If StringIsAlpha($filename) Then MsgBox(0, "file1 : ", $filename) ElseIf $filename = "" Then MsgBox(0, "file2 : ", $filename) Else RunWait('"' & @ComSpec & '" /c "' & $tempScriptName & '"', @SW_HIDE) EndIf WEnd FileClose($search) EndIf If you want to see what @ComSpec is doing then change the @SW_HIDE parameter to @SW_SHOW and use the /k switch instead of /c. Edit: Added FileClose() to close the handle. I have tried your code I still get the same error message. I left the space between '" /k "' & $tempScriptName ... but still get the same error. Is it possible that runwait does not take in $tempScriptName Thanks Link to comment Share on other sites More sharing options...
SadBunny Posted April 17, 2007 Share Posted April 17, 2007 I have tried your code I still get the same error message. I left the space between '" /k "' & $tempScriptName ... but still get the same error. Is it possible that runwait does not take in $tempScriptNameThanksJust for debugging purposes, let a msgbox show the complete string that you are trying to run with the Run() command, to see what exactly is the string. And have it placed on the clipboard, by ClipPut(), so you can post it here.It's very possible that you are overlooking something in creating the commandline string for the Run command, so looking at the string that's actually created for the Run command might clear up possible oversights of this sort. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
BrettF Posted April 17, 2007 Share Posted April 17, 2007 Just for debugging purposes, let a msgbox show the complete string that you are trying to run with the Run() command, to see what exactly is the string. And have it placed on the clipboard, by ClipPut(), so you can post it here. It's very possible that you are overlooking something in creating the commandline string for the Run command, so looking at the string that's actually created for the Run command might clear up possible oversights of this sort. Like this: Global $filename, $exeName, $tempScriptName FileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk") If $search <> -1 Then While 1 $filename = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) If StringIsAlpha($filename) Then MsgBox(0, "file1 : ", $filename) ElseIf $filename = "" Then MsgBox(0, "file2 : ", $filename) Else ClipPut($tempScriptName) EndIf WEnd FileClose($search) EndIf Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 Let's try a different way to solve this. Try this. Global $filename, $exeName, $tempScriptName FileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk") If $search <> -1 Then While 1 $filename = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) If StringIsAlpha($filename) Then MsgBox(0, "file1 : ", $filename) ElseIf $filename = "" Then MsgBox(0, "file2 : ", $filename) Else $parameter = FileGetShortcut($tempScriptName) If Not @error Then MsgBox(0, 'debug', '"' & $parameter[0] & '" ' & $parameter[2] & ', ' & $parameter[1]) RunWait('"' & $parameter[0] & '" ' & $parameter[2], $parameter[1]) EndIf EndIf WEnd FileClose($search) EndIf Link to comment Share on other sites More sharing options...
icemanV Posted April 17, 2007 Author Share Posted April 17, 2007 Hi I did what you said. The string looks good. "P:\LINKS\chieht\Start_All\REX.lnk". Then I tried the using the actual string on the commmand RunWait('"' & @ComSpec & '" /k "' & '"P:\LINKS\chieht\Start_All\REX"' & '"', @SW_SHOW). I still get the error directory name is invalid. Is my syntax correct? Link to comment Share on other sites More sharing options...
icemanV Posted April 17, 2007 Author Share Posted April 17, 2007 Let's try a different way to solve this. Try this. Global $filename, $exeName, $tempScriptName FileChangeDir("P:\LINKS\chieht\Start_All") MsgBox(0, "Directory: ", @WorkingDir) Global $search = FileFindFirstFile(@WorkingDir & "\*.lnk") If $search <> -1 Then While 1 $filename = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File :", $filename) $tempScriptName = @WorkingDir & '\' & $filename MsgBox(0, "script dir :", $tempScriptName) If StringIsAlpha($filename) Then MsgBox(0, "file1 : ", $filename) ElseIf $filename = "" Then MsgBox(0, "file2 : ", $filename) Else $parameter = FileGetShortcut($tempScriptName) If Not @error Then MsgBox(0, 'debug', '"' & $parameter[0] & '" ' & $parameter[2] & ', ' & $parameter[1]) RunWait('"' & $parameter[0] & '" ' & $parameter[2], $parameter[1]) EndIf EndIf WEnd FileClose($search) EndIf I tried your set of codes it worked!!! Thanks. What I don't understand where did you get your variable $parameter. I did not see you declaring the array anyway. Please share...=) Thanks people Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 Too many double quotes. Should look like this RunWait('"' & @ComSpec & '" /k "' & 'P:\LINKS\chieht\Start_All\REX' & '"', @SW_SHOW) Link to comment Share on other sites More sharing options...
MHz Posted April 17, 2007 Share Posted April 17, 2007 I tried your set of codes it worked!!! Thanks. What I don't understand where did you get your variable $parameter. I did not see you declaring the array anyway. Please share...=)Thanks peopleFileGetShortcut() creates the array. An example is in the help file for more on FileGetShortcut(). $parameter is created in the same line as FileGetShortcut(). I am not use MustDeclareVar settings, so assigning a variable is as valid as declaring a variable to initialize it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now