• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3298
  • Last Modified:

WMI Win32_UserAccount Returning Domain Users Instead of Local

I have a situation where, running the WMI Query "Select * from Win32_UserAccount" returns all of the domain users when connected to any desktop in the domain.

How can I modify the query to return only the local users for that machine?
0
cefranklin
Asked:
cefranklin
  • 2
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
Returns a list of all the user accounts found on the local computer.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
    Wscript.Echo objUser.Name
Next
0
 
Meir RivkinFull stack Software EngineerCommented:
0
 
cefranklinAuthor Commented:
Sorry, this code works but, looking specifically for WMI
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Look at the example in http://msdn.microsoft.com/en-us/library/windows/desktop/aa394507(v=vs.85).aspx - just provide the computer name as domain name (and no username) to restrict to local accounts. E.g. as WQL:
select * from Win32_UserAccount where Domain = 'TheComputer'

Open in new window

0
 
cefranklinAuthor Commented:
Restriciting by domain to the local pc works. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now