Sign in to follow this  
Followers 0
iXX

[SOLVED] Running associated files as different user.

8 posts in this topic

#1 ·  Posted (edited)

Hi!

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

Thanks

 

Edited by iXX
Solved

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

iXX,

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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)
        Exit
EndIf

 

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


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

Share this post


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

 

Share this post


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] & '"')
Else
    ; do domething here - error message, or perhaps FileOpenDialog() to manually select a file
EndIf

 

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