Get Ipconfig, NetworkDrives and Printers in a text file from a single .vbs ?

Hello Experts,

What i would like to do, is a vbs (WinNT compatible) runned from a floppy, that create a text file and retrieve "network" infos like this (or so ;) ) :

########################################
ComputerName : <computer name>
IP : <ip adress>
Gateway : <gateway adress>
Network Drives (in alphabetical order) :
     <drive letter>: <path>
Printers :
     <printer name>: <path (if network printer)> <display "[#]" if default, nothing if not>
########################################

The text file created should be called a:\<username>.txt

-

I have this piece of code, but it's not optimized and well presented:

Dim objSocket, WSHShell ,WshNetwork,objWMIService,colItems,oDrives

On Error Resume Next
strComputer = "."
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
Set WSHShell = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives

Set fs = CreateObject("scripting.filesystemobject")
Set fs = fs.CreateTextFile(WSHShell.username & ".txt", True)
Set objSocket = CreateObject("MSWinsock.Winsock")

fs.Write "INFORMATIONS ORDINATEUR"
fs.Write "  Nom de l'ordinateur : " & WSHShell.ComputerName & Chr(13) & Chr(10)
fs.Write "  Adresse IP : " & objSocket.localip & Chr(13) & Chr(10)

fs.Write Chr(13) & Chr(10)

fs.Write "IMPRIMANTE(S) RESEAU(X) :"
For Each objItem In colItems
    fs.Write "  Nom: " & objItem.Caption & Chr(13) & Chr(10)
    fs.Write "  Par Defaut: " & objItem.Default & Chr(13) & Chr(10)
    fs.Write "  Nom du Driver: " & objItem.DriverName & Chr(13) & Chr(10)
    fs.Write "  Reseau: " & objItem.Network & Chr(13) & Chr(10)
    fs.Write "  Port: " & objItem.PortName & Chr(13) & Chr(10)
    fs.Write Chr(13) & Chr(10)
Next

fs.Write "LECTEUR(S) RESEAU(X) :"
For i = 0 to oDrives.Count - 1 Step 2
   fs.Write "  Unité " & oDrives.Item(i) & " = " & oDrives.Item(i+1) & Chr(13) & Chr(10)
Next

fs.Close

*This code doesn't retrieve printers on NT (wscript compatibility ???).

-

Thank in advance for your hard work ;)
Cédric
BadAstronautAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shiju SasidharanAssoc Project ManagerCommented:
hi try this

>>Enumerating Local Network Resources

http://vbnet.mvps.org/index.html?code/network/wnetenumresource.htm

;-)
Shiju
0
Shiju SasidharanAssoc Project ManagerCommented:
Hi
me again

>>Obtaining the IP Address Table
http://vbnet.mvps.org/index.html?code/network/getipaddresstable.htm

;-)
Shiju
0
BadAstronautAuthor Commented:
Hello Shiju,

Thx for the links but this is not what i looking for.

I need a VisualBasicScript file that i could run from a floppy on both WinNT and Win2K, that created a text file containing all the "network" infos.

Will continue my searches ;)

++
Cédric
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

David LeeCommented:
Hi, Cédric.

I'm not sure if this is what you're looking for, but here's a script that collects the type of information you indicated you want and writes it out to a file.  Change the file name and path of the output file and give the script a try.

-- BDF


Wscript.Echo "Here we go."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\SystemInfo.Txt")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True",,48)
'Process TCP/IP settings for all NICs with IP enabled
Wscript.Echo "Processing TCP/IP information"
objFile.Writeline "**** IPConfig Information"
For Each objItem in colItems
    objFile.Writeline vbTab & "Caption: " & objItem.Caption
    objFile.Writeline vbTab & "DefaultIPGateway: " & ParseArray(objItem.DefaultIPGateway)
    objFile.Writeline vbTab & "Description: " & objItem.Description
    objFile.Writeline vbTab & "DHCPEnabled: " & objItem.DHCPEnabled
    objFile.Writeline vbTab & "DHCPLeaseExpires: " & objItem.DHCPLeaseExpires
    objFile.Writeline vbTab & "DHCPLeaseObtained: " & objItem.DHCPLeaseObtained
    objFile.Writeline vbTab & "DHCPServer: " & objItem.DHCPServer
    objFile.Writeline vbTab & "DNSDomain: " & objItem.DNSDomain
    objFile.Writeline vbTab & "DNSDomainSuffixSearchOrder: " & objItem.DNSDomainSuffixSearchOrder
    objFile.Writeline vbTab & "DNSEnabledForWINSResolution: " & objItem.DNSEnabledForWINSResolution
    objFile.Writeline vbTab & "DNSHostName: " & objItem.DNSHostName
    objFile.Writeline vbTab & "DNSServerSearchOrder: " & ParseArray(objItem.DNSServerSearchOrder)
    objFile.Writeline vbTab & "IPAddress: " & ParseArray(objItem.IPAddress)
    objFile.Writeline vbTab & "IPEnabled: " & objItem.IPEnabled
    objFile.Writeline vbTab & "IPSubnet: " & ParseArray(objItem.IPSubnet)
    objFile.Writeline vbTab & "MACAddress: " & objItem.MACAddress
    objFile.Writeline vbTab & "WINSEnableLMHostsLookup: " & objItem.WINSEnableLMHostsLookup
    objFile.Writeline vbTab & "WINSPrimaryServer: " & objItem.WINSPrimaryServer
    objFile.Writeline vbTab & "WINSSecondaryServer: " & objItem.WINSSecondaryServer
    objFile.Writeline ""
Next
Set colItems = Nothing
Set objWMIService = Nothing
'Process Network Drive Information"
Wscript.Echo "Processing Network Drive information"
objFile.Writeline "**** Network Drive Information"
Set objNetwork = CreateObject("Wscript.Network")
Set objDrives = objNetwork.EnumNetworkDrives
For x = 0 To (objDrives.Count - 2) Step 2
    objFile.Writeline vbTab & "Drive " & objDrives(x) & " is connected to " & objDrives(x+1)
Next
objFile.Writeline ""
Set objDrives = Nothing
'Process Network Printer Information
Wscript.Echo "Processing Network Printer information"
objFile.Writeline "**** Network Printer Information"
Set objPrinters = objNetwork.EnumPrinterConnections
For x = 0 To (objPrinters.Count - 2) Step 2
    objFile.Writeline vbTab & "Printer port " & objPrinters(x) & " is connected to " & objPrinters(x+1)
Next
Set objPrinters = Nothing
Set objNetwork = Nothing    
'Clean up
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Wscript.Echo "All done, have a nice day."

Function ParseArray(arrItems)
    strTemp = ""
    If IsArray(arrItems) Then
        For x = 0 To UBound(arrItems)
            strTemp = strTemp & IIf(x = 0, "", ", ") & arrItems(x)
        Next
    End If
    ParseArray = strTemp
End Function

Function IIf(bolCondition, varTrue, varFalse)
   If bolCondition Then
       IIf = varTrue
   Else
       IIf = varFalse
   End If
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BadAstronautAuthor Commented:
Thx a lot ;)

Works perfectly.

++
Cédric
0
David LeeCommented:
You're welcome.  Thank you for the A.
0
BadAstronautAuthor Commented:
Hello and Happy Nu Yeah :)

I adapted your script for my needs and if works so well on W200 & XP, but, can get it to work on NT, give me an error @line5 :

********** File.vbs

Dim WshNetwork,objWMIService,colItems,oDrives,oPrinters
strComputer = "."
On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set fs = CreateObject("scripting.filesystemobject")
Set fs = fs.CreateTextFile(WshNetwork.username & ".txt", True)
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True",,48)

fs.Writeline "********** INFORMATIONS ORDINATEUR"
fs.Writeline ""
fs.Writeline vbTab & "Nom de l'ordinateur : " & WshNetwork.ComputerName
For Each objItem in colItems
    fs.Writeline vbTab & "Adresse IP          : " & ParseArray(objItem.IPAddress)
    fs.Writeline vbTab & "Masque              : " & ParseArray(objItem.IPSubnet)
    fs.Writeline vbTab & "Passerelle          : " & ParseArray(objItem.DefaultIPGateway)
    fs.Writeline ""
Next

fs.Writeline ""
fs.Writeline ""

Set oPrinters = WshNetwork.EnumPrinterConnections
fs.Writeline "********** IMPRIMANTE(S) RESEAU(X)"
fs.Writeline ""
For x = 0 To (oPrinters.Count - 2) Step 2
    fs.Writeline vbTab & "Printer port " & oPrinters(x) & " is connected to " & oPrinters(x+1)
Next

fs.Writeline ""
fs.Writeline ""

Set oDrives = WshNetwork.EnumNetworkDrives
fs.Writeline "*********** LECTEUR(S) RESEAU(X)"
fs.Writeline ""
For i = 0 to oDrives.Count - 1 Step 2
   fs.Writeline vbTab & "Unité " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
Next

fs.Writeline ""
fs.Writeline ""

fs.Writeline "********** CONFIG IP"
fs.Writeline ""

Function ParseArray(arrItems)
    strTemp = ""
    If IsArray(arrItems) Then
        For x = 0 To UBound(arrItems)
            strTemp = strTemp & IIf(x = 0, "", ", ") & arrItems(x)
        Next
    End If
    ParseArray = strTemp
End Function

Function IIf(bolCondition, varTrue, varFalse)
   If bolCondition Then
       IIf = varTrue
   Else
       IIf = varFalse
   End If
End Function

********** File.vbs

If you could help, thx in advance.
Will give you some extra points if you tell me how to do :)
If not, thanks anyway :D

++
Cédric
0
David LeeCommented:
I don't think WMI comes with NT.  I think it's something that has to be added on.  Here's a link to the Microsoft download page: http://www.microsoft.com/downloads/details.aspx?FamilyID=afe41f46-e213-4cbf-9c5b-fbf236e0e875&DisplayLang=en

Before downloading, try checking Add/Remove Programs, Windows Components to make sure it isn't offered as an option there.

No need to give extra points, although I appreciate the thought.  This is all part of this one solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.