Sign in to follow this  
Followers 0
Doppio

RunAsSet

5 posts in this topic

Hi.

There are 2 admin local accounts on my local PC. How can a use an if statement so that if one account is not active, or not found the other account does the RunAs Command?

If Not IsAdmin() Then 

RunAsSet("john","@LogonDomain", "password") 
;if user not found
RunAsSet("Peter","@LogonDomain", "password")
run('DST.exe')

     
EndIf

Thank you.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm not familiar with what Windows has built in the registry to keep track of the users... you could check using an if statement for that...

But if I get what you're trying to say, the best way to do that is to check to see if the User's folder directory exists. (Keep in mind that this only works for Windows Xp as Vista and older operating systems user folder directory may be different)

If Not IsAdmin() Then 
If CheckUser("john")=1 Then
RunAsSet("john",@LogonDomain, "password") 
run('DST.exe')
ElseIf CheckUser("Peter")=1 Then
RunAsSet("Peter",@LogonDomain, "password")
run('DST.exe')
Else
Msgbox(0,"","No Valid Admin Found")
EndIf
EndIf
    

Func CheckUser($user)
$check=FileExists("C:\Documents and Settings\"&$user)
If $check=0 Then
Return 0
Else
Return 1
EndIf
EndFunc

To check to see if the user is an administrator... you can use (if needed)

$cmd = Run(@ComSpec & "", @SystemDir, @SW_SHOW, 7)

; Write the desired commands + RETURNs to the child's STDIN
StdinWrite ($cmd, "net localgroup administrators" & @CRLF & "exit" & @CRLF)
Edited by CrewXp

Share this post


Link to post
Share on other sites

Thank you. it wold be nice if there was a way to do a look-up of the users, or maybe a UserExists function, but anyway appreciate your help.

Share this post


Link to post
Share on other sites

The only way I know of to look up users (administrators), is the last bit of code I posted in my post above. It read the available Admins on the computer

This also might work (havn't tried)

$oMyError = ObjEvent("AutoIt.Error", "ComError")
Local $objDomain = ObjGet("WinNT://" & @ComputerName & "" )
Dim $filter[2] = ["user"]
$objDomain.Filter = $filter
For $aUser In $objDomain
   ConsoleWrite($aUSer.Name & "|" & $aUSer.Profile & @LF)
Next
;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc  ;==>ComError

More complicated though. But glad it worked.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Macros in quotes is just a string, meaning that when you're using @LogonDomain in your script like that,

you are actually saying that the domain is named @LogonDomain. Drop the quotes...

Edit :

MsgBox(64, "", "@LogonDomain vs " & @LogonDomain)
Edited by Helge

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