Jump to content

RunAsSet


Recommended Posts

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.

Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...