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

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
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 User on Workstation


Question:

I was wondering it there is a way to find out on which workstation a user is logged in. The script has to search a domain an give me the workstation name.

Answer:

Trying to get this information is a complicated process. The most reliable method is to have an agent running on each workstation that reports the logon/logoff information to a server which maintains a repository of this information for on-demand reporting.

User code:

The one I use may not be great, but I can't query each machine as we have 50,000 + on our network. Here is a snip from one of my scripts that does this..

Note: Not all environments use the home directory attribute. Also, if a user goes idle for a period of time, network drive letters go into a disconnected state and until the user attempts to access them. In both of these situations, a test for a user accessing the share may fail. Another issue might be if the user is logged on to multiple workstations as I'm not sure if each separate logged on location is reported with this method.

:IDgetLoggedIn
BoxText("Finding Logged in Machines...")
ErrorMode(@OFF)
oUser = ObjectOpen(StrCat("WinNT://" , Domain , "/" , User, ",user"))
ErrorMode(@CANCEL)
If oUser == 0 Then IDGetLoggedInMess=StrCat("Cannot locate Domain: " , Domain , " or user account: " , User, " does not exists.")
If oUser == 0 Then Return
userHome = oUser.HomeDirectory
If userHome == "" Then IDGetLoggedInMess=StrCat("Home Server for user ", User," not specified.")
If userHome == "" Then Return
sName = Arrayize(userHome, "\")
fService = ObjectOpen(StrCat("WinNT://" , Domain , "/" , sName[2] , "/LanmanServer"))
ss = fService.Sessions
LoggedOn = ""
hEnum = ObjectCollectionOpen(ss)
While 1
  Session = ObjectCollectionNext(hEnum)
  If Session == 0 Then Break
  If StrLower(Session.User) == StrLower(User)
     LoggedOn = StrCat(LoggedOn ,@TAB, Session.Computer)
  EndIf
  ObjectClose(Session)
EndWhile
ObjectCollectionClose(hEnum)
If LoggedOn == ""
  IDGetLoggedInMess=StrCat("User: " , User," is not logged on.")
Else
   IDGetLoggedInMess=LoggedOn
EndIf
ObjectClose(fService)
ObjectClose(oUser)
Return

Article ID:   W17091
File Created: 2007:07:03:14:28:16
Last Updated: 2007:07:03:14:28:16