Jump to content

Run Script Error


JoeUser007
 Share

Recommended Posts

  • Moderators

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

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

Link to comment
Share on other sites

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

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

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

oooh that makes sense :)

ok thanks ^^

EDIT: ahh another question :P

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

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

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

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