Sign in to follow this  
Followers 0
this-is-me

Fake Shellexecute

8 posts in this topic

#1 ·  Posted (edited)

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?

Share this post


Link to post
Share on other sites



I am afraid that it may have problems working. The HKCR is not very sure with all this new programs that uses the {uncomprensible hashes}.

Am I wrong?

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I fugured it out. Thanks. Very nice the idea of looking for the $fltp value in that way. Great :ph34r:

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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...


Who else would I be?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Just before the new blue ui it worked fine.


Who else would I be?

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