Jump to content

How to find User on Console 0


Recommended Posts

Hi,

i desperately try to find a script or tool that shows the user logged into console 0 of a machine. I'm running an autoit script within a service account so @username will return the user of that account.

i want to know if real (human) user has logged onto the machine and get his name or id..

THX

I suggest this could be an extension for UDF compinfo.au3?

Link to comment
Share on other sites

Try this:

func _getLocalUser($strComputer)
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
    if isObj($objWMIService) then
        $colComputer = $objWMIService.ExecQuery ("Select UserName from Win32_ComputerSystem")
        For $objComputer in $colComputer
            return $objComputer.UserName
        Next 
    EndIf
    return 0
EndFunc

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

MsgBox(0, "", _getLocalUser("-"))
MsgBox(0, "", @UserName)

Func _getLocalUser($strComputer)
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
    If IsObj($objWMIService) Then
        $colComputer = $objWMIService.ExecQuery ("Select UserName from Win32_ComputerSystem")
        For $objComputer In $colComputer
            Return $objComputer.UserName
        Next
    EndIf
    Return 0
EndFunc
I changed your last EndIf to EndFunc.

(I did not test under the OP's conditions.)

[size="1"][font="Arial"].[u].[/u][/font][/size]

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...