WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Current User List


Here is an application showing the users logged in each machine (it's similar to the tool System Policy Editor in Office Resource Kit)

The logged user information can be retrieved from the registry and all the users logged in the remote machine.(the users logged from terminal for instance)

The "user logged to the machine" info is kept in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
location in the 'DefaultUserName' key, and the domain name is also here in the DefaultDomainName key.

The other users details are in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList 
subkey. Here when you count the "RefCount" reg dword, if it's bigger than zero, it means that the user logged in the corresponding machine...

#DefineFunction GetCurrentUserList(computername)
   userlist = ""
	;Connect Remote Registry
	errormode(@off)
	hnd = RegConnect(computername,@REGMACHINE)
	errormode(@cancel)
	if hnd==0
		return 0
	endif
	;Retrieve the value from the specified subkey..DefaultUserName
	loggedUser = RegQueryValue(hnd, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon[DefaultUserName]")
	
	;Retrieve the value from the specified subkey..DefaultDomainName
	domainName = RegQueryValue(hnd, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon[DefaultDomainName]")
	If StrTrim(domainName) <> "" Then domainName = StrCat(domainName,"\")
   userlist = StrCat(domainName,loggedUser)

   ;Find all other logged users on the specified machine..
   ;ProfileList => RefCount
	
	;open for the ProfileList subkey path...
	hprofkey = RegOpenKey(hnd, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
	keylist = RegQueryKeys(hprofkey)
	For x = 1 to ItemCount(keylist,@tab)
		profile = ItemExtract(x,keylist,@tab)
		refCountProp = RegQueryValue(hnd, StrCat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\",profile,"[RefCount]"))
		If refCountProp > 0 
			profpath = RegQueryExpSz(hnd,StrCat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\",profile,"[ProfileImagePath]"))
			If profpath <> "" 
				user = ItemExtract(-1,profpath,"\")
				userlist = StrCat(userlist,@tab, user)
			EndIf
		EndIf
	next
	
	RegCloseKey(hprofkey)
	RegCloseKey(hnd)

	Return StrTrim(userlist)
#EndFunction


pcname = "RAE"
ret = GetCurrentUserList(pcname)
if ret == 0
  Message(StrCat("GetCurrentUserlist Error on ",pcname),"Unable to Connect to Remote Machine")
endif
if ret == "*NONE*"
 Message(StrCat("GetCurrentUserlist Error on ",pcname),"No Users Logged in.")
endif
AskItemList(StrCat("GetCurrentUserlist on ",pcname),ret,@tab,@unsorted,@single)


Article ID:   W16225
File Created: 2004:03:30:15:43:30
Last Updated: 2004:03:30:15:43:30