Skip navigation

How can I use a script to quickly get information about current username, computer name, and domain?

A. The following script, which you can download here , queries the network object from a VBScript script and outputs current information.


Dim objNet
On Error Resume Next 

Set objNet = CreateObject("WScript.Network") 
If err.Number &lt> 0 Then 'If error occured then display notice
    Wscript.Echo "Error create Network object" & err.number, err.description
    err.Clear
End if

Wscript.Echo "User Name is " & objNet.UserName
Wscript.Echo "Computer Name is " & objNet.ComputerName
Wscript.Echo "Domain Name is " & objNet.UserDomain

Set objNet = Nothing
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish