Link to home
Start Free TrialLog in
Avatar of pedram_ir68
pedram_ir68

asked on

Show computer name

I need a vbscript that if I put a user name then it would give me the computer number ,which that user is currently logged in domain. Appreciate everyone's help.

Best,
P.A
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, you can't really do that....at least very quickly.....without some pre-preparation steps.  To accomplish what you need, you would have to connect to every computer in your domain (without knowing whether they're on or not) and check the logged in user until you find it.  This could take hours per search.

On the other hand, if you follow the options here:
https://www.experts-exchange.com/questions/26525370/Has-anyone-created-an-in-out-board-using-PSLoggedon-before.html

and set up a logon and logoff script that writes user activity to text files, you can immediately query those text files to find out who logged on where.

Regards,

Rob.
You could Google and download NBSTAT.  Command line usage:  nbtstat -a [Machine name]

You could also check out http://www.spiceworks.com
Oops.  Typo should have been NBTSTAT not nbstat.
Avatar of pedram_ir68
pedram_ir68

ASKER

It is possible to do NBTSTAT  -a [User name]
Because I neeed to find out who is logged into which PC on the domain,
You really can't do that reliably with NBTSTAT (at least I never have).  It's best to run a script against all of the computers in realtime that will send the results to a text file.  You will need to add some error checking.  For one-offs, you can use PSLOGGEDON from the SysInternals PSTools suite.

Sample code:
strComputer = InputBox ("Enter Computer Name","Who's LoggedOn")
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
  ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
  Wscript.Echo "User: " & objComputer.UserName
Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rob for your reply. I ran the script for 4 hours but it didnt generate any text file that includes whose logged on to which PC. It didnt give ant error too.
Do you see a command prompt that shows you that it is connecting to each computer?  How far does it get?
the command prompt appears for 10 seconds and then it goes away. please see the attachment.
script.bmp
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
exacly what I was looking for.
Great. Thanks for the grade.

Regards,

Rob.