Jump to content

Check multiple admin accounts with isadmin?


Recommended Posts

Can someone confirm I am doing this right?

Its not working but I dont know if its the script or what. I can not find an example that tries 2 admin accounts.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x / NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

Opt("RunErrorsFatal", 0) ;Enables the Admin account checking to continue on vs. kicking out error and quiting
DirCreate("c:\SvcTools\files")
FileInstall("C:\Documents and Settings\USER\Desktop\scripts\AutoIT3\Jumpclient\xwin32.msi", "C:\SvcTools\files\")
;
RunAsSet("administrator", @ComputerName, 'password1')
RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
    If @error = 0 Then
    $PW = 0
    Else
    RunAsSet("administrator", @ComputerName, 'password2')
    RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)
        If @error = 0 Then
        $PW = 1
        Else
        MsgBox(4096, "Admin account", "Unknown Admin Logon. Contact your administrator. ERROR:xclient")
        Exit
        EndIf
    EndIf
;
If Not IsAdmin() Then
        If $PW = 0 Then
        RunAsSet('administrator', @Computername, 'password1')
        RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")
        RunAsSet()
        Else
        RunAsSet('administrator', @Computername, 'password2')
        RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")
        RunAsSet()          
        EndIf
    Else
    RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")
EndIf
Link to comment
Share on other sites

What version of AutoIt are you using? RunAsSet() is no longer part of AutoIt. The credentials now go directly into the parameters of RunAs() or RunAsWait().

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What version of AutoIt are you using? RunAsSet() is no longer part of AutoIt. The credentials now go directly into the parameters of RunAs() or RunAsWait().

:idea:

OH FFS :) 3.0 i think. I dont do much of this so I reuse old scripts to figure stuff out.

if i upgrade i could lose all my old scripts? :(

Link to comment
Share on other sites

DO you know an example i could use? do I still need:

Opt("RunErrorsFatal", 0)

and

all this?

RunAsSet("administrator", @ComputerName, 'password1')

RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)

If @error = 0 Then

$PW = 0

Else

RunAsSet("administrator", @ComputerName, 'password2')

RunWait(@ComSpec & " /c dir ", "", @SW_HIDE)

If @error = 0 Then

$PW = 1

Else

MsgBox(4096, "Admin account", "Unknown Admin Logon. Contact your administrator. ERROR:xclient")

Exit

EndIf

EndIf

Link to comment
Share on other sites

This is enough:

If RunAs("UserName", @ComputerName, "Pa$$word", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    ; Worked
    ConsoleWrite("Worked..." & @LF)
Else
    ; Failed
    ConsoleWrite("Failed..." & @LF)
EndIf

Assuming you have the current version of AutoIt.

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is enough:

If RunAs("UserName", @ComputerName, "Pa$$word", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    ; Worked
    ConsoleWrite("Worked..." & @LF)
Else
    ; Failed
    ConsoleWrite("Failed..." & @LF)
EndIf

Assuming you have the current version of AutoIt.

:idea:

Hmm.. guss i have to relean how to do this. I dont really understand everything going on there. Also I dont see how that tries two admin passwords to see which is right.
Link to comment
Share on other sites

Hmm.. guss i have to relean how to do this. I dont really understand everything going on there. Also I dont see how that tries two admin passwords to see which is right.

Hi,

have a look at helpfile. Code with the return values.

Success: The PID of the process that was launched.

Failure: Returns 0 and sets @error to non-zero. -> Start second try with second password...

That's what Psalty's code does. Change the else tree to a second RunAs with the second password. Just get the returns of RunAs and recode.

;-))

Stefan

P.S: Heading for soup.....

Edited by 99ojo
Link to comment
Share on other sites

  • 4 weeks later...

Hi,

have a look at helpfile. Code with the return values.

Success: The PID of the process that was launched.

Failure: Returns 0 and sets @error to non-zero. -> Start second try with second password...

That's what Psalty's code does. Change the else tree to a second RunAs with the second password. Just get the returns of RunAs and recode.

;-))

Stefan

P.S: Heading for soup.....

How does this look??? And thanks for all your help.

Opt("RunErrorsFatal", 0) ;Enables the Admin account checking to continue on vs. kicking out error and quiting
DirCreate("c:\SvcTools\files")
FileInstall("C:\Documents and Settings\USER\Desktop\scripts\AutoIT3\Jumpclient\xwin32.msi", "C:\SvcTools\files\")
;

If IsAdmin() Then
    RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")   
EndIf
;
If RunAs("Administrator", @ComputerName, "Password#1", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait( "administrator","password#1","0","msiexec /i C:\SvcTools\files\xwin32.msi")
Else
   If RunAs("Administrator", @ComputerName, "Password#2", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait( "administrator","password#2","0","msiexec /i C:\SvcTools\files\xwin32.msi")
   Else
        MsgBox(4096, "Admin account", "Unknown Admin Logon. Contact your administrator. ERROR:xclient") 
   EndIf
EndIf
Link to comment
Share on other sites

That's going to run it twice, if the user is already an admin. Take advantage of ElseIf:

If IsAdmin() Then
    RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")
ElseIf RunAs("Administrator", @ComputerName, "Password#1", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait("administrator", "password#1", "0", "msiexec /i C:\SvcTools\files\xwin32.msi")
ElseIf RunAs("Administrator", @ComputerName, "Password#2", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait("administrator", "password#2", "0", "msiexec /i C:\SvcTools\files\xwin32.msi")
Else
    MsgBox(4096, "Admin account", "Unknown Admin Logon. Contact your administrator. ERROR:xclient")
EndIf

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That's going to run it twice, if the user is already an admin. Take advantage of ElseIf:

If IsAdmin() Then
    RunWait("msiexec /i C:\SvcTools\files\xwin32.msi")
ElseIf RunAs("Administrator", @ComputerName, "Password#1", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait("administrator", "password#1", "0", "msiexec /i C:\SvcTools\files\xwin32.msi")
ElseIf RunAs("Administrator", @ComputerName, "Password#2", 0, @ComSpec & " /c VER", @WorkingDir, @SW_HIDE) Then
    RunAsWait("administrator", "password#2", "0", "msiexec /i C:\SvcTools\files\xwin32.msi")
Else
    MsgBox(4096, "Admin account", "Unknown Admin Logon. Contact your administrator. ERROR:xclient")
EndIf

:mellow:

Thats way sexier.. Thanks again!

and duh. that was kind of dumb of me as far as running it twice.

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...