PC Review
Forums
Newsgroups
Windows XP
Windows XP WMI
distinguish between local or domain account?
Forums
Newsgroups
Windows XP
Windows XP WMI
distinguish between local or domain account?
![]() |
distinguish between local or domain account? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
The script below obtains the groups and their users on the local machine
(both local and domain accounts), but I'm trying to figure out how to determine whether they are local or domain users. This has to run effectively in a situation where the computer is joined to the Domain, but the current logged-in user has logged in to the local machine. I tried adding a '.domain' to the objGroup but it is not recognized. Thanks much for any help. -CPSharp strComputer = "." Set colGroups = GetObject("WinNT://" & strComputer & "") colGroups.Filter = Array("group") For Each objGroup In colGroups Wscript.Echo objGroup.Name For Each objUser in objGroup.Members Wscript.Echo vbTab & objUser.Name Next Next |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Chris Sharp wrote:
> The script below obtains the groups and their users on the local machine > (both local and domain accounts), but I'm trying to figure out how to > determine whether they are local or domain users. This has to run > effectively in a situation where the computer is joined to the Domain, but > the current logged-in user has logged in to the local machine. > I tried adding a '.domain' to the objGroup but it is not recognized. Thanks > much for any help. > (snip) Hi Note that for the WinNT provider, your script will run faster if you use the actual computer name instead of "." (use the WScript.Network object to obtain the computer name, see example below). To determine if the user is a domain user or not, you need to parse the ADsPath property of the user. Here is a script that will return only local users as well as "NT AUTHORITY" builtin accounts (e.g. "Authenticated Users", "INTERACTIVE" etc.): Set objWshNet = CreateObject("WScript.Network") strComputer = objWshNet.ComputerName Set colGroups = GetObject("WinNT://" & strComputer & "") colGroups.Filter = Array("group") For Each objGroup In colGroups Wscript.Echo objGroup.Name For Each objUser in objGroup.Members If InStr(1, objUser.ADsPath, "/NT AUTHORITY/", vbTextCompare) > 0 Then Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath Elseif InStr(1, objUser.ADsPath, "/" & strComputer & "/", vbTextCompare) _ > 0 Then Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath End If Next Next -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/co...er/default.mspx |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks Torgeir for the help! That's what I was needing exactly.
-CPSharp "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message news:euteMbxVEHA.1164@tk2msftngp13.phx.gbl... ><clip> > > Note that for the WinNT provider, your script will run faster if you > use the actual computer name instead of "." (use the WScript.Network > object to obtain the computer name, see example below). > > To determine if the user is a domain user or not, you need to parse > the ADsPath property of the user. Here is a script that will return > only local users as well as "NT AUTHORITY" builtin accounts (e.g. > "Authenticated Users", "INTERACTIVE" etc.): > > > Set objWshNet = CreateObject("WScript.Network") > strComputer = objWshNet.ComputerName > > Set colGroups = GetObject("WinNT://" & strComputer & "") > colGroups.Filter = Array("group") > For Each objGroup In colGroups > Wscript.Echo objGroup.Name > For Each objUser in objGroup.Members > If InStr(1, objUser.ADsPath, "/NT AUTHORITY/", vbTextCompare) > 0 Then > Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath > Elseif InStr(1, objUser.ADsPath, "/" & strComputer & "/", vbTextCompare) _ > > 0 Then > Wscript.Echo vbTab & objUser.Name & " ADsPath: " & objUser.ADsPath > End If > Next > Next > > > > -- > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway > Administration scripting examples and an ONLINE version of > the 1328 page Scripting Guide: > http://www.microsoft.com/technet/co...er/default.mspx |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

