Get the logged on username in .VBS

This uses a simple vbs script I made (Using a function to get user input from Rob van der Woude) to get your input for a computer name or ip address on your Windows Domain, and returns the currently logged in user.

This makes a nice icon you can click anytime, and with a single line type (or paste) the computer’s address and voila’ you get a nice alert box with the currently logged in username! Just copy paste the following script into a new blank txt file, save and rename to WhosloggedIn.vbs It’s as easy as pie! The script leverages the WMI to ask for username. Many enterprise managment applications have similar features, but are slower to pull up. This is for those quick access trouble calls where you need it quick, and dirty! ūüėõ Script could be used as a base for expanding into collecting all the currently logged in users across the domain, and what computer they are logged in to.

'Get remote logged in user vbs script written by Jason Green http://green.cx strComputer = UserInput( "Enter Computer Name:" ) Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2") Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem") For Each objComputer in colComputer Wscript.Echo objComputer.UserName Next Function UserInput( myPrompt ) ' This function Written by Rob van der Woude http://www.robvanderwoude.com ' Check if the script runs in CSCRIPT.EXE If UCase( Right( WScript.FullName, 12 ) ) = "CSCRIPT.EXE" Then ' If so, use StdIn and StdOut WScript.StdOut.Write myPrompt & " " UserInput = WScript.StdIn.ReadLine Else ' If not, use InputBox( ) UserInput = InputBox( myPrompt ) End If End Function

*Please not that this requires administrative¬†authority¬†on the client machines. Which in a domain, shouldn’t be a problem.

We will be happy to hear your thoughts

Leave a reply

Skip to toolbar