Mental Jetsam

By Peter Finch

Archive for April 1st, 2007

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) "

Posted in VBScript | Leave a Comment »