Sign in to follow this  
Followers 0
MrBedo

Can't run .exe

8 posts in this topic

#1 ·  Posted (edited)

I'm fairly new to this AutoIT game and was just wondering if someone could help me out.

I've got the following very basic script which simply runs an .exe if it finds it. The problem is, when it tries to run it I get a message saying 'Cannot find ini file'.

If FileExists("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe") Then

Run("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe")

There is an ini file in the same folder as the exe, and if I run the exe the usual way by double clicking it then it runs fine.

Do I have to call the ini file before the script runs the exe or something like that?

Like I said, I'm new to all this 'automating the boring jobs' stuff!

thanks in advance for any help

Edited by MrBedo

Share this post


Link to post
Share on other sites



    Run("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe")

Run() does not start a file. It tells windows to run a command line. If you enter what's between the quotes in your run statement into a command line window, it wont work for exactly the same reason.

A correct command line would be:

Run('"C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe"')

Compare the quotes to see the difference.

Share this post


Link to post
Share on other sites

Function Reference
Run 
--------------------------------------------------------------------------------

Runs an external program.


Run ( "filename" [, "workingdir"[, flag]] )
 

 

Parameters

filename The name of the executable (EXE, BAT, COM, or PIF) to run. 
workingdir [optional] The working directory. 
flag [optional] The "show" flag of the executed program:
  @SW_HIDE = Hidden window
  @SW_MINIMIZE = Minimized window
  @SW_MAXIMIZE = Maximized window 

 

Return Value

Success: The PID of the process that was launched.
Failure: Depends on RunErrorsFatal; see Remarks.

 

Remarks

To run DOS (console) commands, try RunWait(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)

After running the requested program the script continues. To pause execution of the script until the spawned program has finished use the RunWait function instead.

By default the script will terminate with a fatal error if the Run function fails. To set @error to 1 as an indication of failure, see AutoItSetOption.


 

Related

RunAsSet, RunErrorsFatal (Option), RunWait 
 

Example

Run("Notepad.exe", "", @SW_MAXIMIZE)

:) hope this helps key words Working Directory read the bove...


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

:)  hope  this helps key words Working Directory  read the bove...

Sorry, but what has the Working Directory to do with his problem?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks both for your help.

Sugi - It didn't seem to make any difference by adding the ' ' around the statement, but I understand what you're saying.

Beerman - Adding the working directory to the end of the statement seemed to do the trick and it now runs as it should.

Thanks again to you both, especially for such quick replies!

Edited by MrBedo
1 person likes this

Share this post


Link to post
Share on other sites

Sorry, but what has the Working Directory to do with his problem?

<{POST_SNAPBACK}>

if a executable calls for an ini file or whatever else file. you have to denote which folder the executable is to be ran in so it knows where to look for the files that it is looking for. i hope i explained this correctly.

 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

if a executable calls for an ini file or whatever else file [...]

Sorry, my fault. I should have read the first post instead of simply guessing that it's the common problem with the quotes.

Share this post


Link to post
Share on other sites

Yea, the quotes (although in many cases are the first place to look for a mistake) are not the problem.

I believe this might need a path as well, you could try one of these:

If FileExists("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe") Then
Run("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe","C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\")

If FileExists("C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\uninstal.exe") Then
Run("uninstal.exe","C:\Program Files\Canon\PrnUninstall\PCL PrinterDriver\")

Specifying a path would be like running the program from that directory. You might also consider a Runwait() if you don't have to do anything in this process, but need to do something after. ( I usually use other functions like monitoring a window or proccess.)


AutoIt3, the MACGYVER Pocket Knife for computers.

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