Sign in to follow this  
Followers 0
Trax

IsLoggedIn?

5 posts in this topic

I know it has to exist yet searching yields nada. I am trying to find a function that simply determines if the computer is logged in to. 

e.g. if no one is logged in (sitting at the ctrl-alt-del screen) I don't want to do anything. If someone is logged in I want to display a msgox.

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@Trax there are a number of ways to do it. One of the simplest is with qwinsta at the command line. Something like this:

qwinsta console /SERVER:<machine name or IP>

will give you the username of the user that is logged in at the console (seating in front of the PC). Take a look at the different parameters to see your options for RDP sessions, service accounts, etc.

A few more lines, but you can also do it through a WMI call:

;====Get Logged in Users
$sPC = <PC name or IP>
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sPC & "\root\cimv2")
$aSystem = $oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")

    If IsObj($aSystem) Then
        For $objItem In $aSystem
            ConsoleWrite("Name: " & $objItem.username & @CRLF)
        Next
    EndIf

 

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thanks JLogan3o13. I am kind of surprised there isn't a UDF or something but in thinking about it maybe it isn't necessary. I only want to display a msgbox if someone is logged in but does it matter? Displaying a msgbox even when no one is logged in won't hurt anything will it?

Share this post


Link to post
Share on other sites

Do you mean displaying a msgbox on the remote PC? If so, what are you using to do so? If you wanted the user to see the MsgBox, you would need to ensure you are making it interact with their session.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I'm not sure, but I think that the WMI call might pick up non-interactive users - for example, Scheduled Tasks that are running under a user's account. I always use something like the following:

ConsoleWrite("User is logged in: " & _IsLoggedIn() & @LF)

Func _IsLoggedIn()
    If ProcessExists("explorer.exe") Then
        Return True
    Else
        Return False
    EndIf
EndFunc

Not a direct test, but it avoids the problem of showing dialogs when there is no way for a user to click on them.


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0