Sign in to follow this  
Followers 0
RegiOween

Run Associated Files Using Run Function

5 posts in this topic

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 :-)

Share this post


Link to post
Share on other sites



#2 ·  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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0