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

Networks - Servers
plus
plus
plus
plus
plus
plus
plus

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

Find Users Logged on Other Machines


Question:

I have found a few ways in winbatch of looking up the computer name from the IP address. Is there a way to find out who the user is that's logged onto a computer in the network?

Answer:

Try using this code that looks at the remote registry for the logged in user:
#DefineFunction GetRemoteLoggedInUser(computername)
	; connect to the registry of the workstation being queried
	errormode(@off)
	hnd = RegConnect(computername,@regusers)
	errormode(@cancel)
	if hnd==0
		return 0
	endif
	
	; get list of user keys
	userlist = RegQueryKeys(hnd)
	numusers = ItemCount(userlist,@tab)
	RegCloseKey(hnd)
	
	errormode(@off)
	hnd = RegConnect(computername,@regmachine)
	errormode(@cancel)
	if hnd==0
		return 0
	endif
	
	if numusers > 1
		loggedonuser = ItemExtract(2,userlist,@tab)
		hnd2 = RegOpenKey(hnd,StrCat("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\",loggedonuser))
		datatype = RegEntryType(hnd2,"[profileimagepath]")
		path = RegQueryEx(hnd2,"[profileimagepath]",@tab,datatype)
		user = ItemExtract(-1,path,"\")
	else
		user = "*NONE*"
	endif
	
	; cleanup
	RegCloseKey(hnd)
	RegCloseKey(hnd2)
	AddExtender("WWWNT34i.DLL")
	errormode(@off)	
	WNTCancelCon(StrCat(computername,"\ipc$"),@TRUE,@TRUE)
	errormode(@cancel)

	return user
#EndFunction


pcname = "\\FRED"
ret = GetRemoteLoggedInUser(pcname)

if ret == 0
  Message(StrCat("GetRemoteLoggedInUser Error on ",pcname),"Unable to Connect to Remote Machine")
endif

if ret == "*NONE*"
 Message(StrCat("GetRemoteLoggedInUser Error on ",pcname),"No Users Logged in.")
endif

Message(StrCat("GetRemoteLoggedInUser on ",pcname),ret)

Note: Maybe Ping the workstation first to make sure it's accessible.


Article ID:   W16035
File Created: 2004:03:30:15:42:22
Last Updated: 2004:03:30:15:42:22