Jump to content

Fake Shellexecute


this-is-me
 Share

Recommended Posts

Since so many people have trouble "running" files, I thought I would make a fake shellexecute to allow direct "running" of files. You may also select the verb to execute on the file. For those of you who don't know, a verb is like open, edit, print, etc.

func shellexecute($file, $verb)
    $ext = StringTrimLeft($file, StringInStr($file, ".", 0, -1))
    $fltp = RegRead("HKEY_CLASSES_ROOT\." & $ext, "")
    if @error Then $fltp = $ext & "file"
    $defverb = RegRead("HKEY_CLASSES_ROOT\" & $fltp & "\shell", "")
    if $defverb = "" Then $defverb = "Open"
    if $verb = "" Then
  $cmd = RegRead("HKEY_CLASSES_ROOT\" & $fltp & "\shell\" & $defverb & "\command", "")
    Else
  $cmd = RegRead("HKEY_CLASSES_ROOT\" & $fltp & "\shell\" & $verb & "\command", "")
    EndIf
    if @error Then
  $cmd = RegEnumKey("HKEY_CLASSES_ROOT\" & $fltp & "\shell", 1)
  if @error Then Return 2
    EndIf
    $cmd = StringReplace($cmd, "%l", FileGetLongName($file))
    $cmd = StringReplace($cmd, "%1", $file)
    $cmd = StringReplace($cmd, "%*", "")
    for $i = 2 to 9
  $cmd = StringReplace($cmd, "%" & $i, "")
    Next
;Why do I have to do this instead of expandenvstrings?
    $env = StringInStr($cmd, "%", 0, 1)
    if not @error Then
  for $i = 1 to 5 Step 2
    if not StringInStr($cmd, "%", 0, $i) Then ExitLoop
    $envx = StringMid($cmd, StringInStr($cmd, "%", 0, $i) + 1, StringInStr($cmd, "%", 0, $i + 1) - 2)
    $cmd = StringReplace($cmd, "%" & $envx & "%", EnvGet($envx))
  Next
    EndIf
    Run($cmd)
endfunc

Example:

shellexecute("C:\boot.ini", "")

If run with the second parameter, It performs a separate operation on the file.

shellexecute(@ScriptFullPath, "Edit")

@jon, What happened to the tabs in code blocks? It shows fine in edit boxes, but not in the posted page.

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

I think you mean the clsid like {00000001-4FEF-40D3-B3FA-E0531B897F98}. If you do, then no. Those are not referencing file associations. The only thing my script does is find the associated program for a file and launch it.

Who else would I be?
Link to comment
Share on other sites

@jon, What happened to the tabs in code blocks? It shows fine in exit boxes, but not in the posted page.

It seems that a
block ignores tabs, but honours spaces: so you can use 4 spaces for each indentation level
Link to comment
Share on other sites

  • Administrators

Yea, but that means that I would need to re-tidy my script before posting each time. I wonder if there is a setting in the board to fix...

Whenever I've used tabs in the past it's appeared like that and I've had to use spaces to format properly. Sure its a recent thing?
Link to comment
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
 Share

  • Recently Browsing   0 members

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