Jump to content

Administrative Account


 Share

Recommended Posts

i am writing a script for work.

We have 5 different Administrator passwords based on the PC model.

I want to write a script to do a RunAs, but want it to be universal for all of the PCs.

Is there a way to go through the 5 passwords to find out which one works on the current PC the script is running on?

Thanks in advance for any help anybody can provide.

Link to comment
Share on other sites

Seems it would probably make more sense to determine what model of PC it is and use the right password. I guess you could try to watch for an @error with runas and then simply try another password, but you will probably just lock out the account doing it that way.

The simplest way to get the PC model is probably WMI, do some searching around though probably a nice neat UDF around there somewhere.

Oh forgot to mention though, its not really safe to store passwords in the script. Depending on what you need to do you may or may not find a better solution. Kinda depends on what you want to live with.

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

i am writing a script for work.

We have 5 different Administrator passwords based on the PC model.

I want to write a script to do a RunAs, but want it to be universal for all of the PCs.

Is there a way to go through the 5 passwords to find out which one works on the current PC the script is running on?

Thanks in advance for any help anybody can provide.

I can't remember where I found this on the forums otherwise I could give the original author credit by name. I modified the original as it used RunAsSet() which no longer functions. It's not the most secure method in the world, but it does work. Just substitute the username,pass entries with the actual account information. Call the function and it will determine the correct credentials. You can then use $user and $pw in your RunAs command.

#include <Array.au3>

Global $user, $pw

Func AdminCheckLocal()
    Global $user="unknown", $pw="unknown"
    Local $avAdmins[1]
    _ArrayAdd($avAdmins, "username,pass1")
    _ArrayAdd($avAdmins, "username,pass2")
    _ArrayAdd($avAdmins, "username,pass3")
    _ArrayAdd($avAdmins, "username,pass4")
    _ArrayAdd($avAdmins, "username,pass5")

    For $i = 1 to UBound($avAdmins) - 1
        $AdminTest = StringSplit($avAdmins[$i], ",")
        RunAsWait($AdminTest[1], @ComputerName, $AdminTest[2], 0, @ComSpec & " /c " & "echo Running on the "& $AdminTest[1] &" account!>"&@WindowsDir&"\au3admchk.tmp", "", @SW_HIDE)
        If not @error Then
            Global $user = $AdminTest[1]
            Global $pw = $AdminTest[2]
            ExitLoop
        EndIf
    Next

    If FileExists(@WindowsDir &"\au3admchk.tmp") Then
        RunAsWait($AdminTest[1], @ComputerName, $AdminTest[2], 0, @ComSpec & " /c del " & @WindowsDir & "\au3admchk.tmp", "", @SW_HIDE)
    EndIf

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