Mental Jetsam

By Peter Finch

Basic network information using VBScript

Posted by pcfinch on April 1, 2007

The following VBScript runs on MS/Windows and displays the current network information available from the WScript.Network object. The code produces a simple messagebox to display the information. A good reference for this information can be found at www.winguides.com.


Set WshNetwork = WScript.CreateObject("WScript.Network")
CR = chr(13)
'
' Get printers
'
Set Printers = WshNetwork.EnumPrinterConnections
strPrinters = ""
For i = 0 to Printers.Count - 1 Step 2
strPrinters = strPrinters& "  " & Printers.Item(i) & "(" & Printers.Item(i+1) & ")" & CR
Next

'
' Get drives
'
Set Drives = WshNetwork.EnumNetworkDrives
strDrives = ""
For i = 0 to Drives.Count - 1 Step 2
strDrives = strDrives & "  " & Drives.Item(i) & "(" & Drives.Item(i+1) & ")" & CR
Next

MsgBox "WshNetwork.ComputerName = " & WshNetwork.ComputerName & CR &_
"WshNetwork.UserDomain = " & WshNetwork.UserDomain & CR &_
"WshNetwork.UserName = " & WshNetwork.UserName & CR &_
"WshNetwork.AddPrinterConnection (Method) "& CR &_
"WahNetwork.AddWindowsPrinterConnection (Method) " & CR &_
"WshNetwork.EnumPrinterConnections (Method) " & CR &_
strPrinters &_
"WshNetwork.RemovePrinterConnection (Method) " & CR &_
"WshNetwork.SetDefaultPrinter (Method) " & CR &_
"WshNetwork.EnumNetworkDrives (Method) " & CR &_
strDrives &_
"WshNetwork.MapNetworkDrive (Method) " & CR &_
"WshNetwork.RemoveNetworkDrive (Method) "
Advertisements

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

 
%d bloggers like this: