Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Checking user logged onto a remote computer

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,23459
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Checking user logged onto a remote computer - 7/11/2005 1:10:56 PM   
  daos

 

Posts: 2
Score: 0
Joined: 7/10/2005
Status: offline
Hi All,

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.

Can someone please help?
 
 
Post #: 1
 
 RE: Checking user logged onto a remote computer - 7/11/2005 10:40:10 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
First in your script you set:

strUser = "."

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.

(in reply to daos)
 
 
Post #: 2
 
 RE: Checking user logged onto a remote computer - 7/11/2005 11:27:50 PM   
  sdeklerk

 

Posts: 16
Score: 0
Joined: 6/28/2005
From: the Netherlands
Status: offline
Hey crazymatt,

I've tried that piece of code you posted, but I get this error:

Line: 10
Char: 1
Error: Permission denied 'GetObject'
Code: 800A0046

Is this another problem with the fact that I'm running NT?

_____________________________

Admins are lazy, therefor we script =)

(in reply to crazymatt)
 
 
Post #: 3
 
 RE: Checking user logged onto a remote computer - 7/11/2005 11:29:42 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
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.

(in reply to sdeklerk)
 
 
Post #: 4
 
 RE: Checking user logged onto a remote computer - 7/11/2005 11:40:32 PM   
  sdeklerk

 

Posts: 16
Score: 0
Joined: 6/28/2005
From: the Netherlands
Status: offline
tnx for your quick reply crazymatt.

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

_____________________________

Admins are lazy, therefor we script =)

(in reply to crazymatt)
 
 
Post #: 5
 
 RE: Checking user logged onto a remote computer - 7/12/2005 1:12:20 AM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
Np, just glad to help.

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.

(in reply to sdeklerk)
 
 
Post #: 6
 
 RE: Checking user logged onto a remote computer - 7/12/2005 10:29:13 AM   
  daos

 

Posts: 2
Score: 0
Joined: 7/10/2005
Status: offline
Thanks for the response crazymatt.  I tried what you suggested and it works great (on some users).

Now I can have my users connect to this desktop system and only connect if no other user is connected.

Thanks again

(in reply to daos)
 
 
Post #: 7
 
 RE: Checking user logged onto a remote computer - 7/12/2005 11:39:26 AM   
  MartinaL

 

Posts: 3
Score: 0
Joined: 7/11/2005
Status: offline
YOu can check who is logged on to a remote computer from the cmd line using the PSTool psloggedon.

There are many other good command line tools here that allow you to run files on remote computers etc.

YOu can download them from www.sysinternals.com

(in reply to daos)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Checking user logged onto a remote computer Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts