Terenz Posted December 20, 2013 Share Posted December 20, 2013 (edited) Hi guys, I'm on a standard user and i need to start a software with admin right of another user, my os is Wndows 7 I know isn't secure to store this information in an .exe but this is not the subject, simply not work as exepected: RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, "cmd.exe", @SystemDir) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) If Not FileExists(@ScriptDir & "\Core Temp.exe") Then ConsoleWrite("ERROR: FILENOTFOUND" & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, @ScriptDir & "\Core Temp.exe", @SystemDir) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, @ScriptDir & "\Core Temp.exe", @ScriptDir) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 1, @ScriptDir & "\Core Temp.exe") If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 2, @ScriptDir & "\Core Temp.exe") If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 4, @ScriptDir & "\Core Temp.exe") If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) ERROR: 1 ERROR: 1 ERROR: 1 ERROR: 1 ERROR: 1 Cmd start without problem ( but is not elevated ). That software require admin rights for be executed and the console give me ERROR: 1 and the software will not start. Where is the mistake? Thanks Edited December 20, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
orbs Posted December 20, 2013 Share Posted December 20, 2013 Terenz, do yourself a favor: when it comes to scripting, no white space in path names! yes, it's possible, but you'll have to mess with double-quotes & single-quotes and that will mess your script pretty badly. also quoting will cripple some DOS operations, so just avoid it. with "Core Temp.exe" renamed to "CoreTemp.exe", your code works just fine for me, all flags tested, with or without working directory specified. 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 Link to comment Share on other sites More sharing options...
Terenz Posted December 20, 2013 Author Share Posted December 20, 2013 (edited) What did you test? You have a standard user? Not work as the same like my first post: If FileExists("C:\CoreTemp.exe") Then RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, "C:\CoreTemp.exe") If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Else ConsoleWrite("ERROR: FILENOTFOUND" & @CRLF) EndIf Result = ERROR: 1 I'm disagree about the "space path", yes you can remove the space form the name of the .exe but @ScriptDir is a macro and the path can have space, anyway that's another story Edited December 20, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 20, 2013 Share Posted December 20, 2013 This thread helped me a lot with running as an administrator. '?do=embed' frameborder='0' data-embedContent>> Basically put this code before you execute the run command. EnvSet("__COMPAT_LAYER", "RunAsInvoker") Also this may help you too. '?do=embed' frameborder='0' data-embedContent>> Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2013 Share Posted December 20, 2013 Try this change to the RunAs command, it puts quotes around the program name to be run. RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, '"' & @ScriptDir & "\Core Temp.exe" & '"' ) There's a double quote inside 2 singles, then the program information, followed by another double quote inside 2 singles again. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Terenz Posted December 20, 2013 Author Share Posted December 20, 2013 (edited) @BrewManNH Not work, same error @jazzyjeff I'll check EDIT: Checked, same errors EnvSet("__COMPAT_LAYER", "RunAsInvoker") Run(@ScriptDir & "\CoreTemp.exe") If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, '"' & @ScriptDir & "\Core Temp.exe" & '"' ) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Edited December 20, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 20, 2013 Share Posted December 20, 2013 Try this EnvSet("__COMPAT_LAYER", "RunAsInvoker") RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, '"' & @ScriptDir & "\Core Temp.exe" & '"' ) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Link to comment Share on other sites More sharing options...
Terenz Posted December 20, 2013 Author Share Posted December 20, 2013 Is not the same i have already do? Anyway i have tested it not work, same error Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 20, 2013 Share Posted December 20, 2013 No it wasn't the same. You were running the command against the Run function. I had you run it against the RunAs function. Try modifying the following registry key: HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystemEnableInstallerDetection Set the DWORD value to 0. This is recommended by Microsoft in a domain environment. Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 20, 2013 Share Posted December 20, 2013 I looked at the string that you had to execute the exe, and the quotes didn't seem right. Try copying and pasting this, and change the credentials EnvSet("__COMPAT_LAYER", "RunAsInvoker") RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, '"' & @ScriptDir & '\Core Temp.exe"') If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Link to comment Share on other sites More sharing options...
Terenz Posted December 20, 2013 Author Share Posted December 20, 2013 (edited) I have tested again with C:Soft.exe ( so i don't have any quotes problem ) and not work. I don't have understand why i have to edit the EnableInstallerDetection, the software is not an installer: This option SHOULD be used to disable the automatic detection of installation packages that require elevation to install I have try to set that key to zero on the admin account...tested again...well nothing Edited December 20, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
jazzyjeff Posted December 20, 2013 Share Posted December 20, 2013 How about executing it using cmd /c. EnvSet("__COMPAT_LAYER", "RunAsInvoker") RunAs("Admin_Username", @ComputerName, "Admin_Password", 0, @ComSpec & ' /c "' & @ScriptDir & '\Core Temp.exe"') If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Link to comment Share on other sites More sharing options...
AdamUL Posted December 20, 2013 Share Posted December 20, 2013 If you need the whole script elevated, then try this solution. I have used it many times without major issues. Global $sAdminUser = "Admin_Username" Global $sAdminPassword = "Admin_Password" Global $sDomain = @ComputerName ;Re-run the script under the Admin account. If @UserName <> $sAdminUser And Not IsAdmin() And @Compiled Then RunAs($sAdminUser, $sDomain, $sAdminPassword, 0, @AutoItExe) Exit EndIf ;Re-run the script, request, and run with Admin Token for Admin account in Windows Vista and Higher. If @UserName = $sAdminUser And Not IsAdmin() And Not StringRegExp(@OSVersion, "_(XP|200(0|3))") And @Compiled Then If ShellExecute(@AutoItExe, "", "", "runas") Then Exit Else Exit MsgBox(16 + 262144, "Error", "Unable to elevate to Admin due to UAC.") EndIf EndIf ;Put rest of the script here. Run("cmd.exe", @SystemDir) If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) If Not FileExists(@ScriptDir & "\Core Temp.exe") Then ConsoleWrite("ERROR: FILENOTFOUND" & @CRLF) Run('"' & @ScriptDir & '\Core Temp.exe"') If @error Then ConsoleWrite("ERROR: " & @error & @CRLF) Here is a >thread where I helped another person with a similar issue, but the script needed to be customized for this domain. Adam Link to comment Share on other sites More sharing options...
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