PC Review Forums Newsgroups Windows XP Windows XP WMI distinguish between local or domain account?

Reply

distinguish between local or domain account?

 
Thread Tools Rate Thread
Old 20-06-2004, 07:33 PM   #1
Chris Sharp
Guest
 
Posts: n/a
Default distinguish between local or domain account?


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


  Reply With Quote
Old 20-06-2004, 10:32 PM   #2
Torgeir Bakken \(MVP\)
Guest
 
Posts: n/a
Default Re: distinguish between local or domain account?

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
  Reply With Quote
Old 21-06-2004, 11:21 PM   #3
Chris Sharp
Guest
 
Posts: n/a
Default Re: distinguish between local or domain account?

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



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off