iXX Posted December 2, 2015 Posted December 2, 2015 (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 registry2.) write the scriptThanks Edited December 3, 2015 by iXX Solved
Kovacic Posted December 2, 2015 Posted December 2, 2015 https://www.autoitscript.com/autoit3/docs/functions/RegWrite.htm We will lead you to water, but not help you drink C0d3 is P0etry( ͡° ͜ʖ ͡°)
orbs Posted December 2, 2015 Posted December 2, 2015 (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 December 2, 2015 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
Kovacic Posted December 2, 2015 Posted December 2, 2015 (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 December 2, 2015 by Kovacic C0d3 is P0etry( ͡° ͜ʖ ͡°)
iXX Posted December 3, 2015 Author Posted December 3, 2015 (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 December 3, 2015 by iXX
orbs Posted December 3, 2015 Posted December 3, 2015 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 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
iXX Posted December 3, 2015 Author Posted December 3, 2015 Thanks, SOLVED! 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...
orbs Posted December 3, 2015 Posted December 3, 2015 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 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now