I have gone through several versions of this and cannot seem to figure out why this does not work.
I originaly had this all done in Sub's called from a main body and got rid of the sub's in hopes of trapping any errors but I cannot seem to capture any errors.
Thanks
John Fuhrman
Titan Global Services
faq329-6766
I originaly had this all done in Sub's called from a main body and got rid of the sub's in hopes of trapping any errors but I cannot seem to capture any errors.
Code:
On Error Resume Next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strPathtoTextFile = "F:\-- AddPrinter Scripts\"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM BankPrinters.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
WScript.Echo "Bind to Computer Object."
WScript.Echo "Error: " & Err.Number
WScript.Echo "Error (Hex): " & Hex(Err.Number)
WScript.Echo "Source: " & Err.Source
WScript.Echo "Description: " & Err.Description
Err.Clear
End If
objRecordset.MoveFirst
Do Until objRecordset.EOF
WScript.Echo "Printer Name: " & vbTab & vbTab & objRecordset.Fields.Item("PrinterName")
WScript.Echo "Printer IP: " & vbTab & vbTab & objRecordset.Fields.Item("PrinterIP")
WScript.Echo "Printer Driver: " & vbTab & objRecordset.Fields.Item("PrinterDriver")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_" & objRecordset.Fields.Item("PrinterIP")
objNewPort.Protocol = 1
objNewPort.HostAddress = objRecordset.Fields.Item("PrinterIP")
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_
objRecordset.MoveNext
Loop
Code:
"PrinterIP","PrinterName","PrinterDriver"
"10.6.102.128","202 BR1_OPS2","HP LaserJet 5"
Thanks
John Fuhrman
Titan Global Services
faq329-6766