Jump to content

[SOLVED] Running associated files as different user.

Recommended Posts


Let say, I have (in windows registry)  ".PRG"  extension associated to:   "C:\Program Files\Program\Program.exe" -r "%1" %*

But now I need to run this *.PRG files as different user, probably using:

RunAs ( "USER", "COMPUTER", "PASSWORD", 1, "C:\Program Files\Program\Program.exe" -r "%1" %*" )

Please help me to:

1.) modify my registry

2.) write the script



Edited by iXX
Link to post
Share on other sites


your RunAs usage is correct, but for the 'program' parameter: you must enclose it all in single-quotes, so the double-quotes within will maintain their original purpose. something like this:

RunAs ( "USER", "COMPUTER", "PASSWORD", 1, '"C:\Program Files\Program\Program.exe" -r "%1" %*"' )

and of course, substitute %1 with the target file, and i have no idea what the %* is for, so you'll have to figure that out yourself.

Edited by orbs
Link to post
Share on other sites

You could also just elevate your permissions.. This will stop the script and run it under whoever you want...


$username = ""
 $Domain = "" ; or @Computername
 $PAssword = ""
 If @username <> $username Then
        RunAs( $username, $Domain, $PAssword, 0, @ScriptFullPath, "", @SW_SHOWMINIMIZED)


Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to post
Share on other sites

OK; First, I figured out that the parameters

-r "%*"

probably are not necessary (After I delete them from registry and double click to some *.PRG file, it normally opens in Program.exe).

So, I substitute the registry entry by this:

"C:\Program Files (x86)\AutoIt\AutoIt3_x64.exe" "C:\Scripts\Prg.au3" "%1"

 And the script (C:\Scripts\Prg.au3) look like this:

RunAs ( "USER", @ComputerName, "PASSWORD", 1, '"C:\Program Files\Program\Program.exe" "%1"' )

Now, when I doubleclick to *.PRG file, the "Program.exe" is launched (under proper user), but with no *.PRG file loaded.

Please, how to solve the handing over of the *.PRG file?

Edited by iXX
Link to post
Share on other sites

you did not substitute the %1 with the target file. AutoIt does not know what is %1 ; this is a shell syntax. check the help file to see how AutoIt handles command line parameters, at:

AutoIt -> Using AutoIt -> Command Line Parameters

Link to post
Share on other sites

Thanks, SOLVED!  :D

The proper code of the script is:

RunAs ( "USER", @ComputerName, "PASSWORD", 1, '"C:\Program Files\Program\Program.exe"' & ' "' & $CmdLine[1] & '"' )

Also, the " -r" parameter works too:

RunAs ( "USER", @ComputerName, "PASSWORD", 1, '"C:\Program Files\Program\Program.exe"' & " -r" & ' "' & $CmdLine[1] & '"' )

The " %*" parameter is not working, but even without it, it works like charm. Who knows, why was there...

So, thanks again...:)


Link to post
Share on other sites

iXX, well done!

i would add an error control: check that $CmdLine[1] actually exists, or your script would crash - if, for example, it is accidentally launched not by the context menu command, but by double-click the compiled exe (which you probably come around to use), so no parameters are passed.

If $CmdLine[0] = 1 Then ; exactly one command line parameter - that's normal for context menu initiation
    RunAs("USER", @ComputerName, "PASSWORD", 1, '"C:\Program Files\Program\Program.exe"' & ' "' & $CmdLine[1] & '"')
    ; do domething here - error message, or perhaps FileOpenDialog() to manually select a file


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

    No registered users viewing this page.

  • Create New...