How to Get a LAN ID and Domain Using VBA
System administrators use the VBA language to automate tasks on users' computers. Instead of configuring each computer individually, the administrator just needs to run one file during the user's login processing. You can use VBA to identify the LAN ID, which is the computer's name, and identify the computer's domain name.
Instructions
-
-
1
Right-click the VBA login file you want to edit and select "Open With." Click "Notepad" in the list of programs to open the editor and the VBA code.
-
2
Add the following line of code to retrieve the LAN ID on the computer running the VBA script:
Dim lanid As String
landid = Environ("ComputerName")
-
-
3
Retrieve the fully qualified name for the computer and assign the response to a variable. The following code retrieves the domain name:
Dim domain As String
domain = Environ("UserDomain")
-
4
Print the results to the screen. The following code displays the LAN ID and domain name in the command prompt when the VBA code runs:
Debug.Print domain
Debug.Print lanid
-
5
Save the file and double-click the saved file on your system. Double-clicking the file lets you run it on your system so you can view the results of the code changes.
-
1