Sign in to follow this  
Followers 0
Terenz

RunAs always fail?

13 posts in this topic

#1 ·  Posted (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 by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 :D

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

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

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