JoeUser007 Posted September 24, 2007 Share Posted September 24, 2007 Pretty much what im trying to do is browse my computer for a vb script, then run it. To my knowledge, the code i have should work, but it doesnt, it returns the error "Error: Unable to execute the external program" Run(FileOpenDialog("Script",".","VBS (*.vbs)")) Link to comment Share on other sites More sharing options...
Danny35d Posted September 24, 2007 Share Posted September 24, 2007 You can do it like the code below, but you should check the return value of FileOpenDialog() function before using Run(). Run(@ComSpec & ' /c ' & FileOpenDialog("Script", @ScriptDir,"VBS (*.vbs)"), @TempDir) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 24, 2007 Moderators Share Posted September 24, 2007 Haven't seen anyone nest a dialog before... buy what the hell lol... try this:Run(@ComSpec & ' /c "' & FileOpenDialog("Script",".","VBS (*.*)") & '"', '', @SW_HIDE) 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 More sharing options...
randallc Posted September 24, 2007 Share Posted September 24, 2007 Pretty much what im trying to do is browse my computer for a vb script, then run it. To my knowledge, the code i have should work, but it doesnt, it returns the error "Error: Unable to execute the external program" Run(FileOpenDialog("Script",".","VBS (*.vbs)"))Hi, Or Shellexecute (instead of run) your line.. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
JoeUser007 Posted September 24, 2007 Author Share Posted September 24, 2007 ok well it works now (or at least so far, i still need to mess around with it a bit ) but what i need to know now is why it works instead of what i had before >< first of all, why did i need the "@CompSpec" and "/c" before the filepath? and second, for the section function of run, why did you (smoke) put " " Link to comment Share on other sites More sharing options...
lordofthestrings Posted September 24, 2007 Share Posted September 24, 2007 because internal commands need to be interpreted by your script host (cmd.exe) it's like you would try : start --> run --> dir c:\ --> error on the other hand if you try : cmd /K dir c: (in start --> run) this would work like a charm. why the /C or /K --> try cmd /? Link to comment Share on other sites More sharing options...
SadBunny Posted September 24, 2007 Share Posted September 24, 2007 ok well it works now (or at least so far, i still need to mess around with it a bit ) but what i need to know now is why it works instead of what i had before ><first of all, why did i need the "@CompSpec" and "/c" before the filepath?and second, for the section function of run, why did you (smoke) put " "You need ComSpec and /c when you want to run a command like in the commandline. ComSpec returns the place where your command interpreter (cmd.exe) is located, and /c is a cmd.exe parameter that makes the commandline interface close after it has completed it's work. You want this for commandline-fashion commands, for instance dir c:\ /s /b /ad or something. The suggestion to use @ComSpec to execute commandline commands + example can also be found in the help files.And ShellExecute and Run are different ways to run a program. Only, ShellExecute interfaces with the Windows system ShellExecute API, which makes sure programs are started with certain 'associated' software (so for instance, ShellExecute'ing a .DOC file will nicely open it in word, Running a .DOC file will give an error because .DOC is not an executable itself). Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JoeUser007 Posted September 24, 2007 Author Share Posted September 24, 2007 ah thanks, that makes sence so...run is just like running a line in cmd? but then again.... in the examples when it opens notepad why dont you have to specify @ComSpec? Link to comment Share on other sites More sharing options...
SadBunny Posted September 24, 2007 Share Posted September 24, 2007 ah thanks, that makes sence so...run is just like running a line in cmd? but then again.... in the examples when it opens notepad why dont you have to specify @ComSpec? Well not exactly, 'run' is for executing an executable. But since many commandline commands are not executables but built-in commands that cmd.exe takes (like DIR, try dir c:\ in Start > Run, it will give an error, while cmd.exe does a dir list when issued a dir command), you need to give them to cmd.exe. Luckily cmd.exe has a parameter (/c, check cmd /? from the commandline) which will spawn cmd.exe, execute a commandline command, and exit cmd.exe again. So for running some executable, you don't need to use the command prompt but can just do Run("notepad.exe"). But for running a commandline command like dir, you will need to use cmd.exe's /c parameter (or other parameter, but it's just that /c is what you need in 99% of the cases). So in fact, running @ComSpec [parameters] is the same as running cmd.exe [parameters], only with @ComSpec you don't need to figure out where cmd.exe is located yourself. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JoeUser007 Posted September 24, 2007 Author Share Posted September 24, 2007 (edited) oooh that makes sense ok thanks ^^ EDIT: ahh another question is there any way i can use AutoIt to run CMD lines? Edited September 24, 2007 by JoeUser007 Link to comment Share on other sites More sharing options...
SadBunny Posted September 24, 2007 Share Posted September 24, 2007 oooh that makes sense ok thanks ^^ EDIT: ahh another question is there any way i can use AutoIt to run CMD lines? Please read this thread from begin to end carefully. It has been the exact thing that this whole thread has went on about. Furthermore, the Run() help information contains the exact syntax you need in the first line of the Remarks. For demonstration, try:Run(@ComSpec & " /c " & '"dir c:\windows /s /a > c:\test.txt"',@SystemDir,"",@SW_HIDE)... and then check your C:\ directory for a file called test.txt. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JoeUser007 Posted September 24, 2007 Author Share Posted September 24, 2007 heh maybe that was bad wording... How can i use AutoIt to send cmd lines to a Windows Shell in other words, not running programs from cmd, but say opening a port on windows firewall, which would be netsh firewall set portopening TCP <port> in cmd. In VBScript you have to make a new variable and turn it into a shell, then you can send commands to it, but i dont know how to do it with AutoIt Link to comment Share on other sites More sharing options...
SadBunny Posted September 25, 2007 Share Posted September 25, 2007 heh maybe that was bad wording... How can i use AutoIt to send cmd lines to a Windows Shell in other words, not running programs from cmd, but say opening a port on windows firewall, which would be netsh firewall set portopening TCP <port> in cmd. In VBScript you have to make a new variable and turn it into a shell, then you can send commands to it, but i dont know how to do it with AutoIt Just do:Run(@ComSpec & " /c " & '"netsh firewall set portopening TCP ' & $portToOpen & '"',"",@SW_SHOW) ... to run shell commands. In my test, this works like a charm. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
JoeUser007 Posted September 25, 2007 Author Share Posted September 25, 2007 er....yea now i feel stupid O_O lol thanks a lot guys 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