Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Users on a PC via API 1

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
Some time ago a kind person gave me the following code snippet to find the users on a Windows PC.

<code>

Local lnNormalAccount, cQuery, oResult
#ifndef UF_NORMAL_ACCOUNT
#Define UF_NORMAL_ACCOUNT 0x00000200
#Endif
*!* Clear
strComputer = "."
objWMIService = Getobject("winmgmts:\\"+strComputer+"\root\cimv2")
lnNormalAccount = UF_NORMAL_ACCOUNT
cQuery = Textmerge("select * from win32_useraccount Where AccountType = <<m.lnNormalAccount>> AND Disabled = False")
colItems = objWMIService.ExecQuery(cQuery)

N = 1
For Each objItem In colItems
yname = Transform(Nvl(objItem.Name,''))
yname = Alltrim(yname)
*!* ?yname
Select pcusers
*!* ? oResult.Count
Next
</code>


My problem is:-

Due to 'repairs' on an XP PC I see the following users on the PC named 'TOWER'

All Users.WINDOWS.
All Users
colin
colin.TOWER - I get this user with a rightclick on the Start button.

The 3rd party software has installed under the colin.TOWER path.

The program listed above only gives me

All Users
colin

Has anyone any knowledge of the routine that can modify it to show all of these users?

If I code around it artificially my app may not work on all XP pcs.

I know I could format and reinstall XP on this PC.

Any advice welcome.

Colin
 
Hello Colin,

As far as I understand you find these User Profile Folders. While I don't understand where they come from, All Users is of course no single user, but simply a folder where all common stuff goes. I don't know where .WINDOWS or .TOWER folders come from.

You could simply try the same WMI query without any WHERE conditions to get all users of that computer. This script does this and also displays all the properties of a user, not only it's account name:

Code:
Local lcQuery, lcComputer, loWMIService, loAccounts, loUser, loProperty, lcName

lcComputer = "."
loWMIService = Getobject("winmgmts:\\"+lcComputer+"\root\cimv2")

* no WHERE clause
lcQuery = "select * from win32_useraccount" 
loAccounts = loWMIService.ExecQuery(lcQuery)

For Each loUser In loAccounts
   ? '--- Account: ',loUser.Name,' ---'
   * loop through all properties
   For Each loProperty In loUser.Properties_
      lcName = loProperty.Name
      ? lcName,":", loUser.&lcName.
   EndFor 
EndFor

Bye, Olaf.
 
wow, is it possible to get each stations(computer) name with all the above info i'm getting
 
well, you need a list of computer names, then use these instea of "." in lcComputername.

But if you then query remotely, you need sufficient rights and remote queries need to be enabled. I admit, I really don't know even what. RPC (remote procedure call) there are certainly ports for WMI that need to be opened in the firewall.

One other way to get that info from all computers of a LAN is, use the distribution off an app you update to all computers anyway and let them run this each local, then store the results in a central table.

Bye, Olaf.
 
Thanks Olaf, tried it and it gives me a moniker cannot open file. With my station name though it gives me the same result as the ".".
Will dig into it.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top