TIPS: VBScript : Get Logged in username using VBScript.


  • Using Environment Variable

Set wshShell = WScript.CreateObject( “WScript.Shell” )
strUserName = wshShell.ExpandEnvironmentStrings( “%USERNAME%” )
WScript.Echo “User Name: ” & strUserName

  • Using WshNetwork

Set wshNetwork = WScript.CreateObject( “WScript.Network” )
strUserName = wshNetwork.UserName
WScript.Echo “User Name: ” & strUserName

  • Using ADSI (ADSystemInfo)

Set objSysInfo = CreateObject( “ADSystemInfo” )
strUserName = objSysInfo.UserName
WScript.Echo “User Name: ” & strUserName

  • ADSI (WinNTSystemInfo)

Set objSysInfo = CreateObject( “WinNTSystemInfo” )
strUserName = objSysInfo.UserName
WScript.Echo “User Name: ” & strUserName

  • WMI (Win32_ComputerSystem)

Set objWMI = GetObject( “winmgmts:\\.\root\cimv2” )
Set colItems = objWMI.ExecQuery( “Select * from Win32_ComputerSystem” )
For Each objItem in colItems
strUserName = objItem.UserName
Next

 

Advertisements

One thought on “TIPS: VBScript : Get Logged in username using VBScript.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s