Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Get Current User Remotely

 Keywords:  

Question:

Is there a function to get the current user on a workstation remotely?

Answer:

If you're using NT this should tell you who is logged in:
errormode(@off)
hnd = RegConnect("\\%pcname%",@regusers)
errormode(@cancel)

hnd2=RegOpenKey(hnd,"")
userlist = regquerykeys(hnd2)
numusers = itemcount(userlist,@tab)
RegCloseKey(hnd)

errormode(@off)
hnd = RegConnect("\\%pcname%",@regmachine)
errormode(@cancel)

if numusers > 1
	loggedonuser = itemextract(2,userlist,@tab)
	hnd2 = regopenkey(hnd,"SOFTWARE\Microsoft\Windows
	NT\CurrentVersion\ProfileList\%loggedonuser%")
	datatype = regentrytype(hnd2,"[profileimagepath]")
	path = regqueryex(hnd2,"[profileimagepath]",@tab,datatype)
	pathlen = strlen(path)
	backslash = strindex(path,"\",0,@backscan)
	idlen = pathlen - backslash
	msg = strsub(path,backslash + 1,idlen)
else
	msg = "None"
endif

errormode(@off)
WNTCancelCon("\\%pcname%\ipc$",@TRUE,@TRUE)
errormode(@cancel)

You will have to provide the "pcname". The result is placed in "msg".

I combined this with a dialog so I could check any of thousands of remote workstations to see who, if anyone, is logged on.