Now Reading
Get the logged on username in .VBS
0

Get the logged on username in .VBS

by Jason GreenMay 18, 2010

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.

About The Author
Jason Green
The writer and owner of Green Complex, Jason is an A+ Certified for Computer Hardware egghead and Eagle Scout since 1999 but has been building computers and programming for much longer. An enthusiast to say the least, his hobbies also include photography, video games, and reading. See his proficiencies on Smarterer.

You must log in to post a comment