Cyri Posted June 3, 2010 Posted June 3, 2010 Is there a simple method to detect whether a user is logged into a computer? My script is running as the SYSTEM account in non-interactive mode and I want to detect if a user is logged on to the console of WinXP workstations. I did find the Win32_ComputerSystem class in WMI which has a UserName value which appears to show the console user. I see some posts out there saying that the UserName field isn't consistent. Anyone know of other ways?
Richard Robertson Posted June 3, 2010 Posted June 3, 2010 http://www.codeproject.com/KB/system/logonsessions.aspx This article might help.
Cyri Posted June 4, 2010 Author Posted June 4, 2010 http://www.codeproject.com/KB/system/logonsessions.aspx This article might help. Thanks, that helps explain the different ways to find the information. I was hoping there was already a UDF that had this nailed down already. Time to stop being lazy... For now I'm using this utnil I can find something better. Func IsLoggedOn($strComputer = ".") Dim $objWMIService, $objItem, $colUsers $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colUsers = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem WHERE UserName <> NULL", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) For $objItem in $colUsers Return 1 Next EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now