All Forums >> [Scripting] >> WSH & Client Side VBScript >> Checking user logged onto a remote computer Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Hope someone can help me with this. I am trying to query if a user is logged onto a remote computer and run RPD if there is not user logged on. This is what I have:
' Identifying the User Logged on to a Remote Computer ' Description ' Returns the user name of the user currently logged on to a remote ' computer. To use this script, replace RemoteComputer with the name ' of the remote computer you want to check. ' Script Code strUser = "." strComputer = "BRIPC05" 'Wscript.Echo "Checking computer " & strComputer Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputer = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colComputer Wscript.Echo objComputer.UserName Next If strUser = "." Then Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "mstsc /console z:\BRIPC05.RDP", 0, false else WScript.Quit End If
Now I am a n00b when it comes to vbscript. I thought that if I had the line: If strUser = "." that it would check if a user is logged on and then if there is not a user already logged on then the script will continue and run mstsc.exe, if there is a user logged on then it will just quite.
The problem is that the script starts mstsc no matter what, e.g. if there is a user logged on or not.
Then u never change that value but later you have an if statement that says: If strUser = "." Then Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "mstsc /console z:\BRIPC05.RDP", 0, false
So ofcourse its gonna do whats in the ifstatement nomatter if a user is logged on or not Try this instead.
Good luck with the scripting!
_____________________________
-There is only 10 sorts of people, those who understand binary and those who dont.
Not sure if NT is causing the problem, i do know that you need to be admin of the computer you are trying to run the script on and also the remote computer you are querying.
Hope that helps
/Matt
_____________________________
-There is only 10 sorts of people, those who understand binary and those who dont.
I'm running the script as an admin and I'm an admin on the machine I'm trying to query. The funny thing is that when I query a workstation other than mine then I get the error, but when I query on of our servers then it works, so it must have something to do with permissions of some sort...
FYI, I did get the same error when i tried to run the script another machine with a non admin account though. I have XP on all the machines here though so i cant promies that it should work on nt since i cant test it.
_____________________________
-There is only 10 sorts of people, those who understand binary and those who dont.