exec method WMI

F

future_retro

Hi, I'm trying to use the AddPrinterDriver method of
Win32_PrinterDriver to create a new..... print driver. I can't get my
head round how I need to do this. So far I have

import win32com.client
WBEM =
win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\"
+ "." + r"\root\cimv2")
WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
drv = WBEM.Get("Win32_PrinterDriver").SpawnInstance_()
drv.Properties_('Name').Value = "Marcs Printer 2550"
drv.Properties_('SupportedPlatform').Value = "Windows NT x86"
drv.Properties_('Version').Value = "3"
drv.Properties_('DriverPath').Value = 'C:\\test\\HPZPP034.DLL'
drv.Properties_('InfName').Value = 'C:\\test\\hpc2550d.inf'
method = drv.Methods_('AddPrinterDriver')
InParms = method.InParameters
InParms.Properties_.Item('DriverInfo').Value = drv
drv.ExecMethod_('AddPrinterDriver',InParms)

I'm using spawninstance to create a new object and then editing the
properties of it. I'm then setting the InParameters for the method to
be the new object. When executing the method I get SWbemObjectEx
object not found.

I think I am not setting the DriverInfo correctly, should it be an
object? The MSDN site doesn't say what DriverInfo should be.

Any help would be grand.

Thanks, MW.
 
R

Roger Upole

You probably need to remove the SpawnInstance_() call.
An abstract WMI class as returned by WBEM.Get should work
for the DriverInfo parm, since the concrete Win32_PrinterDriver
instance is what the AddPrinterDriver call is trying to create.

hth
Roger
 
F

future_retro

Got it working, removed spawninstance and the driver path should have
been "C:\\test\\"

Cheers for your help Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top