Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


SWbemObjectEx: Invalid parameter HELP!!!

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,47234
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> SWbemObjectEx: Invalid parameter HELP!!!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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"""
 
 
Post #: 1
 
 RE: SWbemObjectEx: Invalid parameter HELP!!! - 5/20/2007 10:19:15 PM   
  crazymatt

 

Posts: 297
Score: 0
Joined: 3/4/2005
From:
Status: offline
quote:

ORIGINAL: aburt

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.


objNewPort.Put_
FilePath =  Split(WScript.ScriptFullName, WScript.ScriptName)(0) & "hppcp602.inf"


The "_" sign means that you continue on next row, im not sure if thats what you want?
objNewPort.Put_
FilePath =  Split(WScript.ScriptFullName, WScript.ScriptName)(0) & "hppcp602.inf" 
is the same as
objNewPort.Put FilePath =  Split(WScript.ScriptFullName, WScript.ScriptName)(0) & "hppcp602.inf"
 
If thats not the problem im not sure what it is,
you say it woks on some computers but not all? Are there diffrent WSH engines on them, diffrent servicepacks or anything else that is diffrent. Its hard helping when you havent specified what the script is supposed to do (no comments in the code) or without know why it doesnt work all the time.



_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to aburt)
 
 
Post #: 2
 
 RE: SWbemObjectEx: Invalid parameter HELP!!! - 5/22/2007 12:11:10 PM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
OK after much testing and retesting I have narrowed down that the problem I am having with my script comes from the section where I am trying to create a printer port.  On some of my XP machines the port is created and the script is working fine.  On some of the others
I get this error G:\PrinterPriv.vbs(36, 1) SWbemObjectEx: Access denied   (Line 36 is put_ exist)  Does anyone understand why this is happening? btw I did eventually take this portion of the script out and use the command line prnadmin.dll which creates printer ports  but to keep expanding my VB knowledge I wanted to understand why I was having this issue with objNewPort.Put_


Here is the create tcp/ip portion of my script


      

(in reply to crazymatt)
 
 
Post #: 3
 
 RE: SWbemObjectEx: Invalid parameter HELP!!! - 5/22/2007 7:43:29 PM   
  crazymatt

 

Posts: 297
Score: 0
Joined: 3/4/2005
From:
Status: offline
I've done a lil reading and this might be your problem.

http://msdn2.microsoft.com/en-us/library/aa394363.aspx

The Win32_Printer class is derived from CIM_Printer. Before calling SWbemObject.Put_ or IWbemServices::PutInstance for a Win32_Printer instance, the SeLoadDriverPrivilege privilege (wbemPrivilegeLoadDriver for Visual Basic and LoadDriver for scripting monikers) must be enabled. For more information, see Privilege Constants and Executing Privileged Operations. The following VBScript code example shows how to enable the SeLoadDriverPrivilege privilege in script.



  Set objPrinter = GetObject( _
"winmgmts:{impersonationLevel=Impersonate ," _
& "(LoadDriver)}!//./root/cimv2:Win32_Printer")

 
Hope it helps

/CM

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to aburt)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> SWbemObjectEx: Invalid parameter HELP!!! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts