Ever wondered if you could retrieve the network login name of the current user? Well, sure!
If you are familiar with VBScript, you would already have assumed it’s done through Windows Script objects. An example below will get you the user name and display it in a message box:
Dim objNetwork Dim userName Set objNetwork = CreateObject("WScript.Network") userName = objNetwork.UserName WScript.Echo userName
As you see we first declare a variable for an object and a variable that will hold the user name. We then instantiate a
WScript.Network object and set the
objNetwork variable to it. Once we got that, the
UserName property of our object will contain the network logon name which we assign to
userName variable and, finally, show it in a message box via
Can’t be simpler!