lmwinbur
06-10-2002, 03:04 PM
Anyone know who to list all the local groups of a local machine or domain?
Thanks,
Landon.
For Each Process In GetObject("winmgmts:").InstancesOf("Win32_Account")
wscript.echo Process.Name
Next
That’s pretty much all you need to enumerate all the accounts known to the computer.
The above script will echo the name of every account known to the system, including non local accounts, built-in accounts, groups and user’s accounts.
To get to a specific account, you’ll need to filter the info returned by the GetObject methode.
The following script will find accounts with a SIDType greater than 1 “User accounts are 1” and then checks to see if the account is a local account.
I’m not too keen on message boxes, so I included code to create a temp file, write the data to it, display it in notepad and wait for you to close notepad, it will then delete the temp file. The blue sections deals with the accounts, the rest is for the temp file. Delete it if you wish.
‘************************* Local Accounts.vbs *******************************
Set FSo = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
SysFolder = WshShell.Environment("Process")("SystemRoot")
strRandomFileName = FSO.GetTempName
LocAccountReportName = SysFolder & "\temp\" & strRandomFileName
Set PermReport = FSo.CreateTextFile(LocAccountReportName, True)
PermReport.writeline "Local users & groups" & vbNewline
<font color=blue>
For Each Process In GetObject("winmgmts:").InstancesOf("Win32_Account")
If Process.SIDType > 1 Then
If Process.LocalAccount = True Then
PermReport.writeline "Account: " & Process.Name & vbNewline &_
"Description: " & Process.Description & vbNewline & "SID: " &_
Process.SID & vbNewline & "Account type: " & Process.SIDType &_
"= " & AcType(Process.SIDType) & " " & vbNewline & "A/c Status: " &_
Process.Status & vbNewline & "Caption: " & Process.Caption &_
vbNewline & "Local Account: " & Process.LocalAccount & vbNewline
End If
End If
Next
Function AcType(t)
Dim s
Select Case t
Case 1
s = "User Account"
Case 2
s = "Group Account"
Case 3
s = "Domain Account"
Case 4
s = "Alias Account"
Case 5
s = "WellKnownGroup Account"
Case 6
s = "DeletedAccount Account"
Case 7
s = "Invalid Account"
Case 8
s = "Unknown Account"
Case 9
s = "Computer Account"
End Select
AcType = s
End Function
</font color=blue>
PermReport.close
WshShell.run "notepad" & " " & LocAccountReportName, 1, True
':::::::::::::::::::::::::::::::: Clean up :::::::::::::::::::::::
Set DelFile = FSO.GetFile(LocAccountReportName)
DelFile.Delete
Set FSo = Nothing
Set WshShell = Nothing
Set PermReport = Nothing
Set DelFile = Nothing
'::::::::::::::::::::::::::::::::: eNd :::::::::::::::::::::::::::
‘*************************** eNd *******************************
Jama
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.