Sign in to follow this  
Followers 0

Detecting if built in admin account is enabled or disabled

18 posts in this topic

Posted · Report post

I'm working on something to enable the built in admin account on windows 7
ie the one that is hidden on install of windows.

I know how to enable it but i want to be able to detect it so if its already active i don't try and make it active again.

so some sort of function etc that i can run a check with maybe?
im using net user to change it to active

Is there a way to detect it?

any pointers helpfull.

Share this post


Link to post
Share on other sites



Posted (edited) · Report post

WMI rootCIMV2 "SELECT Disabled FROM Win32_UserAccount WHERE Name = 'Administrator'"
or parse Account Active from STDOUT of Run("Net user Administrator") Edited by rover

Share this post


Link to post
Share on other sites

Posted · Report post

WMI rootCIMV2 "SELECT Disabled FROM Win32_UserAccount WHERE Name = 'Administrator'"

I started Scriptomatic but got a little distracted, that's one to add to my function folder. Thanks.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

ConsoleWrite(_IsAdminEnabled() & @CRLF)

Func _IsAdminEnabled()
	Local $oWMIService = ObjGet('winmgmts:localhostrootCIMV2')
	Local $oColItems = $oWMIService.ExecQuery('SELECT * FROM Win32_UserAccount WHERE Name = "Administrator"', "WQL", 0x30)
	If IsObj($oColItems) Then
		For $oItem In $oColItems
			Return $oItem.Disabled = False
		Next
	EndIf
	Return True
EndFunc   ;==>_IsAdminEnabled
Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

"Return $oItem.Disabled = False"

Would that not return false when it is Enabled?

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

If the Admin account is Disabled it returns True, not False. Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

Seems a little unintuitive bud, unless you named it "IsAdminDisabled.

Share this post


Link to post
Share on other sites

Posted · Report post

I wouldn't worry about that line, if the Admin account is enabled then _IsAdminEnabled returns True.

Share this post


Link to post
Share on other sites

Posted · Report post

Must be this brain block I've had of late.

Cheers.

Share this post


Link to post
Share on other sites

Posted · Report post

It's OK. It feels more natural to write the True statement first and then the False statement e.g.
; This is how the majority of users write code.
If _IsAdminEnabled() Then
	; It's True
Else
	; It's False
EndIf

; So using _IsAdminDisabled would result in this.
If _IsAdminDisabled() = False Then
	; It's True
Else
	; It's False
EndIf

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

How about that?

Func _IsAccountDisabled($sUser = @UserName, $sCompName = ".")
Local $aCall = DllCall("netapi32.dll", "int", "NetUserGetInfo", "wstr", $sCompName, "wstr", $sUser, "dword", 1, "ptr*", 0)
If @error Or $aCall[0] Then Return SetError(1, 0, False)
Local $Return = (BitAND(DllStructGetData(DllStructCreate("ptr;ptr;dword;dword;ptr;ptr;dword;ptr", $aCall[4]), 7), 2) <> 0)
DllCall("netapi32.dll", "int", "NetApiBufferFree", "ptr", $aCall[4])
Return $Return
EndFunc

ConsoleWrite(_IsAccountDisabled('Administrator') & @CRLF)
Edited by JFX

Share this post


Link to post
Share on other sites

Posted · Report post

One returns false (guinness) and the other returns true (JFX)

Share this post


Link to post
Share on other sites

Posted · Report post

Yeh, because JFX is checking if the Admin account is disabled.

Share this post


Link to post
Share on other sites

Posted · Report post

lol

I need a few more days off.

Share this post


Link to post
Share on other sites

Posted · Report post

I suppose I'm just an optimistic person and prefer enabled.

Share this post


Link to post
Share on other sites

Posted · Report post

Geez i step out the house and the thread has gone mad..

Many thanks to all who contributed

I was still working on this
$colItems = ""
$Output=""
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL")
If IsObj($colItems) then
   For $objItem In $colItems
	  $Output &= "Caption: " & $objItem.Caption & @CRLF
	  $Output &= "Disabled: " & $objItem.Disabled & @CRLF
	  if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
	  $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_UserAccount" )
Endif

Share this post


Link to post
Share on other sites

Posted · Report post

See post #4 for a working function.

Share this post


Link to post
Share on other sites

Posted · Report post

Using the method of 'net user' and reading the Standard Output Stream >> http://www.autoitscript.com/forum/topic/139260-autoit-snippets/page__pid__981844__st__20#entry981844

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