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

WMI
plus
plus

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

Get Remote Logged in User


Question:

I want to get the current user (the user's Session) on a remote computer.

Answer:

User = "sid"
Password = "nancy"
ComputerName = "computer123"
Locator = ObjectOpen("WbemScripting.SWbemLocator")
;Service = Locator.ConnectServer()
Service = Locator.ConnectServer(ComputerName,"root/cimv2",User,Password)
Security = Service.Security_
Security.ImpersonationLevel = 3
Class = "Win32_ComputerSystem"
Instance = Service.InstancesOf(Class)
hEnum = ObjectCollectionOpen(Instance)
While 1
Obj = ObjectCollectionNext(hEnum)
If Obj == 0 Then Break
LUser = Obj.UserName
EndWhile
ObjectCollectionClose(hEnum)
ObjectClose(Instance)
ObjectClose(Security)
ObjectClose(Service)
ObjectClose(Locator)


message ("RESULTS", StrCat("'",LUser, "' is currently logged on to '",computername,"'"))

Article ID:   W16753
File Created: 2005:02:18:12:22:14
Last Updated: 2005:02:18:12:22:14