Jump to content

If one active administrator on local machine return


NDog
 Share

Recommended Posts

Hi all

I am trying to write a section of a script that will query if active administrators exist on the local machine and return a yes or no value. The logic is to query wmi and if at least one active administrator account is found then return positive value. If completing a scan and nothing found then assume no value.

I am using the advice found There are some parts which don't make sense to me. I will simplify as much as possible to explain.

#include <Array.au3>
$objComputer = ObjGet("WinNT://." )
$objComputer.Filter = _ArrayCreate( "User" )

For $objUser In $objComputer
    Consolewrite( "Name: " & $objUser.Name & @CRLF)
    Consolewrite( "AccountDisabled: " & $objUser.AccountDisabled & @CRLF)
    Consolewrite(@CRLF)
Next

How can I query the values of what is being passed here? Nowhere can I find documentation for the _ArrayCreate function. Also I have no idea how to query the data, eg _ArrayDisplay("User"), _ArrayDisplay($objUser), _ArrayDisplay($objComputer) does not return anything. I do not know how to query the data that is running in this script and am working blind.

This is how I would like the script to work

1) First query groups and get administrators

2) If administrative group user found then pass that user into a function which checks if that user account is enabled or disabled ($objUser.AccountDisabled)

3) return positive / negative result

This script is way off but since I do not know how to query the data I am working with it is the best I can come up with. Any help would be appreciated. Cheers!

#include <Array.au3>

$colGroups = ObjGet("WinNT://.")
$colGroups.Filter = _ArrayCreate("group")

For $objGroup In $colGroups
    For $objUser in $objGroup.Members
        If $objGroup.Name = "Administrators" Then
            ;ConsoleWrite("Local Group: " & $objGroup.Name & @CRLF)
            ;ConsoleWrite("Local User: " & $objUser.name & @CRLF)
            ;Consolewrite(@CRLF)
            CheckEnabled($objUser.name)
        EndIf
    Next
Next

Func CheckEnabled($user)
$objComputer = ObjGet("WinNT://." )
$objComputer.Filter = _ArrayCreate( "User" )
    For $objUser In $objComputer
        Consolewrite( "Name: " & $objUser.Name & @CRLF)
        Consolewrite( "AccountDisabled: " & $objUser.AccountDisabled & @CRLF)
        Consolewrite(@CRLF)
    Next
EndFunc
Link to comment
Share on other sites

First, you're using _ArrayCreate incorrectly. What that function does is simply creates a 21 element 1D array and returns it. You have to assign at least one element of the array, which is put into [0] of the array, and you can optionally pass the function the other 20 elements if you wish to. But you'd have to use it like this "$Array = _ArrayCreate("User")", that will make $Array[0] = "User" and the other 20 elements = "0". You can use _ArrayDisplay to show the array like this "_ArrayDisplay($Array)".

Personally, I'd never use _ArrayCreate because there are much better ways of creating an array, which is why this function is undocumented and will someday be removed.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks for the advice.

I am just hacking up best as I could to make *something* workable. Arrays are very confusion for me. Do you think you could show me how to modify the $colGroups.Filter = _ArrayCreate("group") to be better? Thanks!

Code works but I am afraid latest versions will break it...

; compile as console application!
; script function scans if any other user than administrator is active and returns enabled if true

#NoTrayIcon
#include <Array.au3>

$colGroups = ObjGet("WinNT://.")
$colGroups.Filter = _ArrayCreate("group")

For $objGroup In $colGroups
    For $objUser in $objGroup.Members
        If $objGroup.Name = "Administrators" Then
            ;ConsoleWrite("Local Group: " & $objGroup.Name & @CRLF)
            ConsoleWrite("Admin User: " & $objUser.name & @CRLF)
            ;Consolewrite(@CRLF)
            If $objUser.name <> "Administrator" Then CheckEnabled($objUser.name)
        EndIf
    Next
Next

ConsoleWrite("Disabled")

Func CheckEnabled($UserName)
    $objUser = ObjGet("WinNT://./" & $UserName)
    ;Consolewrite( "Name: " & $objUser.Name & @CRLF)
    ;Consolewrite( "AccountDisabled: " & $objUser.AccountDisabled & @CRLF)
    ;Consolewrite(@CRLF)
    If $objUser.AccountDisabled = False Then
        ConsoleWrite("Enabled")
        Exit
    EndIf
    
EndFunc
Edited by NDog
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...