Jump to content

Recommended Posts

Posted

Could anyone give me insight as to why one would use ShellExecute() instead of Run() to launch an app? I know ShellExecute is good for launching files or printing them.

Original stem idea #394739

A decision is a powerful thing
Posted

Could anyone give me insight as to why one would use ShellExecute() instead of Run() to launch an app?...

ShellExecute allows you to launch a URL in the default browser. i.e. a link in your GUI to an on line help file... when your script is not going to be working with the browser - you just want the user to browse with the app they like.

The same is true for starting a word doc... but you already knew that :-)

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

Yeah, :) I guess I'm asking ...

You can use ShellExecute() to do what Run() can do, so why use Run() or Should one not use ShellExecute() for launching an app like notepad.exe?

A decision is a powerful thing
Posted

Yeah, :) I guess I'm asking ...

You can use ShellExecute() to do what Run() can do, so why use Run() or Should one not use ShellExecute() for launching an app like notepad.exe?

Run returns the PID of the app started and also allows for STDIO.

AFAIK, ShellExecute does neither of those two.

You can launch notepad via ShellExecute if you wish - I see no harm in it. It is in the help file as the example script.

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

ShellExecute is for launching files with their associated program.

Run executes programs only and will return a process ID of the process, this is very important.

RunWait pauses script execution until the external program is complete and then returns the exit code of the program.

There is a _ProcessGet UDF somewhere that can get the exitcodes from a Run() process ID.

Posted

ShellExecute is for launching files with their associated program...

:-) Then we might want to change the example in the help file. :-)
; Open Notepad
ShellExecute("Notepad.exe")

; Open a .txt file with it's default editor
ShellExecute("myfile.txt", "", @ScriptDir, "edit")
If all you want to do is start notepad, then I would think that either should work just fine. If the app supports it, you could start the app (like notepad) and specify a file on the same line. The second line in the example may not start notepad - but you knew that :-)

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

What do you mean change the help file?...

It was just a lighthearted attempt at pointing out that the help file tells users that they can start notepad via ShellExecute and Run has about the same sample code.

Funny that you mentioned speed - I wrote (but deleted) info that said that Run should be faster because of all the stuff ShellExecute has to do... but I decided not to go there. Perhaps I should have... it is one of the differences and the OP might care.

You are correct in all that you have said about the two (no, we really don't have to change the help file). I was just wanting to highlight what you parenthetically included here:

Thats what ShellExecute does, runs a file (or program) with its associated interpreter....

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted

herewasplato and weaponx, THANK YOU!

That's exactly the type of info I was looking for!! Now I understand what is going on with Run() and ShellExecute(). I really don't like using things that I don't understand what they are doing or why they are doing it. Thanks again. Yeah, I saw ShellExecute doing the notepad.exe example so that's how I came across it. I didn't know Run() "passes" info like command line, thus allowing you to send params. I also didn't realize the return differences. That's very important as you've said. Furthermore, haha as you both said (and almost said) yeah I can see now that since ShellExecute is using the API it does require more time to do the same thing Run does. Thanks guys!

A decision is a powerful thing
Posted

500 milliseconds is an immense difference too...ha

I only get a 41 millisecond diff, so ha ha :-)
;get notepad into memory
$process = Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
ProcessClose($process)

$stamp1 = TimerInit()
$process = Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
$diff1 = TimerDiff($stamp1)
ProcessClose($process)

$stamp2 = TimerInit()
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
$diff2 = TimerDiff($stamp2)

MsgBox(0, "Shell minus Run", $diff2 - $diff1)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Posted (edited)

Ok Run is not sending my params. What am I doing wrong? :)

;>>>When I used shellexecute() >>>  ;
;ShellExecute('"I:\Auto-It files\Projects\TSM PlanID Master\inprogress\Client Master List Interface - Options Interface.exe"','Launched_from_Parent '&$thisParentTitletoSend &' '&$ParentWinPosArray[0]+$ParentWinPosArray[2]&' '&$ParentWinPosArray[1],'I:\Auto-It files\Projects\TSM PlanID Master\inprogress')

;now using Run
Run('"I:\Auto-It files\Projects\TSM PlanID Master\inprogress\Client Master List Interface - Options Interface.exe"'&' /Launched_from_Parent /'&$thisParentTitletoSend &' /'&$ParentWinPosArray[0]+$ParentWinPosArray[2]&' /'&$ParentWinPosArray[1],'I:\Auto-It files\Projects\TSM PlanID Master\inprogress')

Edit: Locations were mismatched

Edited by JohnBailey
A decision is a powerful thing
Posted

You might not even need the slashes. Also you could try:

With slashes:

$Path = StringFormat('"I:\Auto-It files\Projects\TSM PlanID Master\inprogress\Client Master List Interface - Options Interface.exe" /Launched_from_Parent /%s /%s /%s', $thisParentTitletoSend, $ParentWinPosArray[0]+$ParentWinPosArray[2], $ParentWinPosArray[1])

Run($Path,'I:\Auto-It files\Projects\TSM PlanID Master\inprogress')
Posted

My edit may have made it sound like I resolved the issue. However, i did not. The way I'm using Run isn't sending params.

A decision is a powerful thing
Posted

You might not even need the slashes. Also you could try:

With slashes:

$Path = StringFormat('"I:\Auto-It files\Projects\TSM PlanID Master\inprogress\Client Master List Interface - Options Interface.exe" /Launched_from_Parent /%s /%s /%s', $thisParentTitletoSend, $ParentWinPosArray[0]+$ParentWinPosArray[2], $ParentWinPosArray[1])

Run($Path,'I:\Auto-It files\Projects\TSM PlanID Master\inprogress')
Both return

The system cannot find the file specified.

A decision is a powerful thing
Posted

There is a _ProcessGet UDF somewhere that can get the exitcodes from a Run() process ID.

OOH! I've been looking for something like this. I'm using AutoIt to control an installer, so I need to use Run() to enable AutoIt to control the installer while it's running, but I want to find out what the exit status of the installer was so I can determine if the installation was successful or not. Right now I'm running the installer inside a .bat file which echoes %ERRORLEVEL% to a temp file... but I keep thinking there's got to be a better way.

How do I find this _ProcessGet UDF?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...