Login | |
|
 |
SWbemObjectEx: Invalid parameter HELP!!! - 5/20/2007 11:57:37 AM
|
|
 |
|
| |
aburt
Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
|
I ran this script on several but not all xp clients I get a SWbemObjectEx: Invalid parameter on the line that has objNewPort.Put_ I going to loose my mind. Somebody Please help. Option Explicit Dim strComputer : strComputer = "." Dim objNetwork : Set objNetwork = CreateObject("WScript.Network") Dim localIP : localIP = ResolveIP(objNetwork.ComputerName) Dim arrIPOct : arrIPOct = Split(localIP, ".") Dim intOct3 : intOct3 = CInt(arrIPOct(2)) Dim intOct4 : intOct4 = CInt(arrIPOct(3)) Dim Location1, Location2, Location3, Location4 Dim Location, IP Dim Printer, FilePath Dim objShell, objNewPort, objWMIService Dim RunErrorToReturn, Results If (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 3 And intOct4 <= 30) Then 'If (intOct3 >= 1 And intOct3 <= 3) And (intOct4 >= 3 And intOct4 <= 30) Then IP = "x.x.1.a" Printer = "-Location1" Location = "Location1" 'WScript.Echo "Match x.x.1.3 - x.x.1.30: " & localIP ElseIf (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 35 And intOct4 <= 62) Then 'ElseIf (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 35 And intOct4 <= 62) Then IP = "x.x.1.b" Printer = "-Location2" Location = "Location2" 'WScript.Echo "Match x.x.1.35 - x.x.1.35: " & localIP ElseIf (intOct3 >= 1 And intOct3 <= 15)And (intOct4 >= 67 And intOct4 <=94) Then 'ElseIf (intOct3 >= 1 And intOct3 <= 15)And (intOct4 >= 67 And intOct4 <=94) Then IP = "x.x.1.c" Printer = "-Location3" Location = "Location3" WScript.Echo "Match x.x.1.67 - x.x.1.94: " & localIP ElseIf (intOct3 >= 1 And intOct3 <= 33) And (intOct4 >= 99 And intOct4 <=126) Then 'ElseIf (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 99 And intOct4 <=126) Then IP = "x.x.1.d" Printer = "-Location4" Location = "Location4" 'WScript.Echo "Match x.x.1.99 - x.x.1.126: " & localIP ElseIf (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 131 And intOct4 <=158) Then 'ElseIf (intOct3 >= 1 And intOct3 <= 15) And (intOct4 >= 131 And intOct4 <=158) Then IP = "x.x.1.e" Printer = "-Location5" Location = "Location5" 'WScript.Echo "Match x.x.1.99 - x.x.1.126: " & localIP End If Function ResolveIP(computerName) Dim objShell : Set objShell = CreateObject("WScript.Shell") Dim objExec : Set objExec = objShell.Exec("ping " & computerName & " -n 1") Dim RegEx : Set RegEx = New RegExp RegEx.Pattern = "\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]" RegEx.IgnoreCase = True RegEx.Global = True ResolveIP = RegEx.Execute(objExec.StdOut.ReadAll)(0).Submatches(0) End Function Set objWMIService = GetObject("winmgmts:"_ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ Set objShell = CreateObject("WScript.Shell") objNewPort.Name = "IP_" & IP objNewPort.Protocol = 1 objNewPort.HostAddress = IP objNewPort.PortNumber = "9100" objNewPort.SNMPEnabled = False objNewPort.Put_ FilePath = Split(WScript.ScriptFullName, WScript.ScriptName)(0) & "hppcp602.inf" 'WScript.Echo FilePath 'This Is For Printer Driver objShell.Run "rundll32 printui.dll, PrintUIEntry /if /b " & Chr(34)& "Printer" & Printer & Chr(34) & " /f "& _ FilePath & " /r " & Chr(34)& "IP_" & IP & Chr(34) & " /m " & """Printer"""
|
|
| |
|
|
|
|
|