Jump to content

IsLoggedIn?


Trax
 Share

Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...