Jump to content
Sign in to follow this  
CarlD

ShellExecuteRaw()

Recommended Posts

CarlD

This UDF takes a raw string and parses it into command and parameters variables, which it passes to ShellExecute() -- or ShellExecuteWait() if variable $vWait is set. I use it to read command strings from an .ini file, which can be executed by entering a short alias, or key. For example, with the following .ini entry I can open the NY Times website in Firefox by simply entering "N":

N="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" http://www.nytimes.com/

ShellExecuteRaw() parses the command string into command and parameter(s), and then returns ShellExecute[Wait]().

 

Func ShellExecuteRaw($R, $vWorkingDir="", $vVerb="", $vWait="")
#cs
    Format raw string as "command", "params" for ShellExecute[Wait]()
    Variables: $R = raw string; $C = command; $D = delimiter; $P = params
    If input var $vWait is set, func returns
        ShellExecuteWait($C, $P, $vWorkingDir, $vVerb)
    otherwise, it returns
        ShellExecute($C, $P, $vWorkingDir, $vVerb)
#ce
    Local $C = $R, $D = " ", $P = ""
    If StringInStr($R, '"') == 1 Then
        $D = '" '
    EndIf
    If StringInStr($R, $D) > 0 Then
        $C = StringTrimRight( $R, StringLen($R) _
            - StringinStr($R, $D) + 2 - StringLen($D) )
        $P = StringTrimLeft( $R, StringInStr($R, $D) )
    EndIf
    Local $ShellFuncName = "ShellExecute"
    If $vWait Then
        $ShellFuncName = $ShellFuncName & "Wait"
    EndIf
    Return Call($ShellFuncName, $C, $P, $vWorkingDir, $vVerb)
EndFunc ; ShellExecuteRaw
Edited by CarlD

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, CarlD. Can you please explain what benefit this gives the user, over using the inherent ShellExecute or Run functions? It looks like I would have to do an IniRead, then call your function, which is more code. Just curious why use this over the built in funcs.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
CarlD

Hi, CarlD. Can you please explain what benefit this gives the user, over using the inherent ShellExecute or Run functions? It looks like I would have to do an IniRead, then call your function, which is more code. Just curious why use this over the built in funcs.

Basically, it takes a Windows CMD.EXE command line (command + parameters) and reformats it for ShellExecute() or ShellExecuteWait(). The only reason to use it would be if you're dealing with user input in the form of a Windows command line and want to pass it to ShellExecute(). The .ini file is one example of when that might occur. There may not be many others; it's a limited-purpose function, but it does do the job.

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  

×