cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Japster24
Level 6

Detect Logged in Users

Does anyone know how to detect the users logged into Windows? I can only have the current user user logged in and need to display a message to log all other users out (if I detect more than one is logged in).

If there's a default installscript action that would be great but I could just as easily use a windows function in my installscript.

Thanks!
Labels (1)
0 Kudos
(2) Replies
Japster24
Level 6

Anyone??? I have a vbscript that I found that I could create a custom action with, but it only seems to detect the person that is logged on currently, not all users on the windows machine.

Option Explicit
Dim objWMIService, objComputer, colComputer, strComputer, counter

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
counter = counter + 1
Wscript.Echo objComputer.UserName & " is logged on"
Wscript.Echo counter & " is the number of users I found"
Next
0 Kudos
Japster24
Level 6

thanks for nothing 🙂

well in case anyone was wondering...here's what i found and it seems to do the trick. check your LogonType here: http://msdn.microsoft.com/en-us/library/aa394189(VS.85).aspx or remove it all together (remove 'Where LogonType = 2' if you want all logged on users)


Option Explicit
Dim objWMIService, objComputer, colComputer, strComputer, numUsers

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery("Select * from Win32_LogonSession Where LogonType = 2")

For Each objComputer in colComputer
numUsers = numUsers + 1

'Wscript.Echo "LogonId: " & objComputer.LogonId & VbCr _
' & "Name: " & objComputer.Name & VbCr _
' & "LogonType: " & objComputer.LogonType & VbCr _
' & "Description: " & objComputer.Description & VbCr _
' & "Description: " & objComputer.Description & VbCr _
' & "Status: " & objComputer.Status

Next

Wscript.Echo numUsers
0 Kudos