Jump to content

Recommended Posts

Posted

Hi, folks!

Is there some way to run associated files that are not executable directly using the RUN function? For example:

Run("C:\PATH\FILE.EXT", "C:\PATH")

With the command above, I receive the message "Error: Unable to execute the external program." It seems that RUN just works with executable files like EXE, COM, BAT, etc.

I tried to use a workaround like this:

Run(@COMSPEC & " /c C:\PATH\FILE.EXT", "C:\PATH", @SW_HIDE)

This command works to execute FILE.EXT using CMD.EXE, but the flag @SW_HIDE doesn't work the way I want, since it hides CMD.EXE window and not FILE.EXT window. My main purpose is run FILE.EXT in a hidden window. If anyone knows some way to do that, even if I have to use some external tool, please explain me how.

Thanks in advance.

Reginaldo O. Andrade

PS: Sorry about possible english errors, I'm from Brazil :-)

  • Moderators
Posted (edited)

Try using this for your run cmd to run the associated program.

$path = "path to the file you want to run"
Run(@ComSpec & " /c Start " & $path, "", @SW_HIDE)

Then you could do a WinWait() and a WinSetState() to hide the program window.

Also you may want to look at WinWaitDelay to shorten the delay in the Window related commands. You could try putting this at the top of your script.

Opt("WinWaitDelay", 75)
Edited by big_daddy
Posted

You are correct in what filetypes that Run() executes as it is state on the help page for Run().

Have a look at Freqently Asked Question Number 6.

http://www.autoitscript.com/autoit3/docs/faq.htm#6

Execute the program that is associated with the file to execute the file, and since you are using the correct program with Run(), the the hide flag should work unless the program does not want to hide.

Posted

big_daddy, I'm actually already using the WinWait / WinSetState functions as a workaround to my script, but you are absolutely right about WinWaitDelay option, this was the solution for my problem. Not using the WinWaitDelay parameter causes my script to pause 250 ms (the default behaviour) after the window appear. Setting this parameter to 0 causes no delay, so the script now is working flawlessly. Many thanks!

Reginald0

  • Moderators
Posted

big_daddy, I'm actually already using the WinWait / WinSetState functions as a workaround to my script, but you are absolutely right about WinWaitDelay option, this was the solution for my problem. Not using the WinWaitDelay parameter causes my script to pause 250 ms (the default behaviour) after the window appear. Setting this parameter to 0 causes no delay, so the script now is working flawlessly. Many thanks!

Reginald0

Glad I was able to help.

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
×
×
  • Create New...