Jump to content

RunAs Help


damon
 Share

Recommended Posts

Hello,

You guys helped me years ago to address logging in with a different account than the user.  I have sense modified it over the years due to laptops syncing with AD which is why you will see 3 different passwords.  So, this script snippet has worked for me in many things i have written but I am all the sudden having an issue getting it to work.  I have verified that the password i am using for the local user account is $pass.  Verified by doing a run as different user on Chrome and cut and pasted the password out of the script just to make sure i was not fat fingering something.  

I get a fail back from RunAs every time.   

Any chance you guys see something i am doing wrong?

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
;#RequireAdmin

If $CmdLine[0] > 0 Then
    If $CmdLine[1] = "/Install" Then RunUpdate()
    Exit
EndIf

;;Will check users account to determine if admin, if not will Run with admin rights --------------------------------------------------------------
;;Varables Start
Local $user = ".\user"
Local $pass = "password1"
Local $pass2 = "password2"
Local $pass3 = "password3"
Local $filetorun = @ScriptFullPath & " /Install"
;;Varables End


If IsAdmin () = 0 Then
    If RunAs ( $user, @CompterName, $pass, $RUN_LOGON_NOPROFILE,$filetorun) = 0 Then
        ;If RunAs ( $user, @ComputerName, $pass2, 0,$filetorun) = 0 Then
            ;If RunAs ( $user, @ComputerName, $pass3, 0,$filetorun) = 0 Then
                ;MsgBox (0,"Installation Error", "This installation was interrupted due to an incorrect Admin Password")
                ;Exit
            ;EndIf
        ;EndIf
    EndIf
    Exit
Else
    Run ($filetorun)
EndIf


Func RunUpdate()
MsgBox(0,"worked","worked")
EndFunc

It always amazes me how one little thing can cause so much havoc

Link to comment
Share on other sites

Why do you have the user name set to ".\user"?  It should just be "user".  You are already specifying the domain as @ComputerName, so the ".\" is not needed.  Also, RunAs requires the user name only for the first argument, not "domain\username".  Also, RunAs does not request the Admin Token when it runs a command, so the account run as does not have full admin rights.  There are workarounds for this, here is one. 

 

Adam

Link to comment
Share on other sites

1 minute ago, AdamUL said:

Why do you have the user name set to ".\user"?  It should just be "user". 

you are right, I just figured out what i was doing.  when i came back to post my update seen your question and that was my fix.  thank you.

It always amazes me how one little thing can cause so much havoc

Link to comment
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
 Share

×
×
  • Create New...