Jump to content

Access to WMI to get SIDs for all users?


 Share

Recommended Posts

Ok - no response on previous lamely-worded question. What I would like to know is: is there a way to access WMI (Windows Management Instrumentation) functions from AutoIt, as you can from Javascript? I need to enumerate the SIDs for all users in profile from a script. Is it possible for the admin in Vista to do this?

V. <_<

Other script code looks like this:

CODE

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _

strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"

objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

For Each objSubkey In arrSubkeys

strValueName = "ProfileImagePath"

strSubPath = strKeyPath & "\" & objSubkey

objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue

Wscript.Echo strValue

Next

Source for above code: http://www.microsoft.com/technet/scriptcen...05/hey0603.mspx

Edited by vatobeto
Link to comment
Share on other sites

Ok - no response on previous lamely-worded question. What I would like to know is: is there a way to access WMI (Windows Management Instrumentation) functions from AutoIt, as you can from Javascript? I need to enumerate the SIDs for all users in profile from a script. Is it possible for the admin in Vista to do this?

V. <_<

Other script code looks like this:

CODE

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _

strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"

objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

For Each objSubkey In arrSubkeys

strValueName = "ProfileImagePath"

strSubPath = strKeyPath & "\" & objSubkey

objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue

Wscript.Echo strValue

Next

Source for above code: http://www.microsoft.com/technet/scriptcen...05/hey0603.mspx

Bump. Nevermind.

I found the beginning to the answer to my inquiry in a post by ArthurB in the thread: "How to explore wmi objects?, without knowing the attributs names"

As follows:

CODE
Func _EnumWMIclassInstances($classname, $servername = ".")

Local $service = ObjGet("winmgmts:\\" & $servername & "\root\cimv2")

Local $security = $service.Security_

$security.ImpersonationLevel = 3

Local $collection = $service.InstancesOf($classname)

For $object In $collection

For $property in $object.Properties_

ConsoleWrite($property.Name & ": " & $property.Value & @CR)

Next

Next

EndFunc

_EnumWMIclassInstances("Win32_Service")

Thanks ArthurB.
Link to comment
Share on other sites

Keep in mind that almost (not quite) anything you can do in VBScript can be done in AutoIt. Get your hands on the latest version of the MS Scriptomatic, which will show you VBScript code for almost anything in the automation interfaces, then translate what you need into AutoIt.

<_<

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

Ok - no response on previous lamely-worded question. What I would like to know is: is there a way to access WMI (Windows Management Instrumentation) functions from AutoIt, as you can from Javascript? I need to enumerate the SIDs for all users in profile from a script. Is it possible for the admin in Vista to do this?

V. <_<

This is an AutoIt script I adapted from a vbs script on http://windowsxp.mvps.org. Works on XP, I haven't tested on Vista.

;based on "SIDlist.vbs by Ramesh Srinivasan, http://windowsxp.mvps.org

#include <Array.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost" 

$AccountList = ""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_UserAccount", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then

    For $objItem In $colItems
        $leftName = StringLeft($objItem.Name, 5)

        Switch $objItem.Name

            Case "HelpAssistant", "SUPPORT_388945a0", "ASPNET"  ;exclude "special" built-in accounts"
                ContinueLoop

            Case $objItem.Disabled <> 0 ; exclude disabled accounts, comment out this and next line to include them
                ContinueLoop

            Case $leftName = "IUSR_"  Or $leftName = "IWAM_"  ;exclude more non-relevant accounts
                ContinueLoop

            Case Else
                $AccountList &= $objItem.Name & " = " & $objItem.SID & @CR
        EndSwitch
    Next

Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_UserAccount")
EndIf

$AccountList = StringTrimRight($AccountList, 1)
$aAccountList = StringSplit($AccountList, @CR)
_ArrayDisplay($aAccountList)
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...