Page 1 of 1 1
Topic Options
#115709 - 2004-03-08 10:25 PM WMI Install Printer
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Ok I know there are other ways to do this... but this is the way I'm trying to do it.. so close, yet so far.
Code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$objPrinter = 'objWMIService.Get("Win32_Printer").SpawnInstance'
$objPrinter.DriverName = "HP Color LaserJet 4550 PCL 6"
$objPrinter.PortName = "IP_127.0.0.1"
$objPrinter.DeviceID = "ScriptedPrinter"
$objPrinter.Location = "Net Admin"
$objPrinter.Network = "True"
$objPrinter.Shared = "True"
$objPrinter.ShareName = "ScriptedPrinter"
$objPrinter.Put



Everything seems to work fine up until $objPrinter.Put, which returns an error 6 "The handle is invalid.".

What am I doing wrong?

Top
#115710 - 2004-03-08 10:54 PM Re: WMI Install Printer
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Why not use the internal KiXtart - ADDPRINTERCONNECTION, SETDEFAULTPRINTER?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#115711 - 2004-03-08 11:04 PM Re: WMI Install Printer
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Because that doesn't create/use a TCP/IP printer port. Only uses a shared printer.
Also I mostly want to figure out if I'm doing something wrong converting my WMI into Kix..

Top
#115712 - 2004-03-08 11:27 PM Re: WMI Install Printer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnport.mspx for a WMI-VBS way to create a printer port.

You should also read the WMI documentation!
Quote:


Windows 2000 and earlier: Instances of Win32_Printer are read-only. Put operations fail with a WBEM_E_PROVIDER_NOT_CAPABLE (wbemErrProviderNotCapable in the scripting API) error (0x80041024).



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp


Edited by sealeopard (2004-03-08 11:29 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#115713 - 2004-03-08 11:49 PM Re: WMI Install Printer
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Going off of info from here:
http://www.microsoft.com/technet/community/scriptcenter/printing/scrprn19.mspx
It is a Windows XP workstation. I am trying to run it on, was trying to convert the WMI VBScript into Kix.

Top
#115714 - 2004-03-09 05:24 AM Re: WMI Install Printer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You're missing the underscore in .PUT_
_________________________
There are two types of vessels, submarines and targets.

Top
#115715 - 2004-03-09 06:17 AM Re: WMI Install Printer
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Yes, I also took the underscore off after "winmgmts:", and .Spawninstance . Not sure what the underscore is used for in the VBScript code.. got all kinds of errors with it when I left it in trying to convert it to kixtart. I've takrn the underscore off on some VBScript WMI queries that I've converted to Kixtart to make it work before.
Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.065 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org