The following works great
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "HP LaserJet 4200 PS"
objDriver.SupportedPlatform = "x86"
objDriver.Version = "Windows 2000, Windows XP and Windows Server 2003"
objDriver.FilePath = "C:\\hp4200ps.inf"
objDriver.InfName = "hp4200ps.inf"
intResult = objDriver.AddPrinterDriver(objDriver)
WScript.Echo intResult
The following gives me an error stating "Not found" on the 3rd line below
(SetPropertyValue) as well as setting a property using the brackets []
ManagementClass mc = new ManagementClass("Win32_PrinterDriver");
ManagementBaseObject inParams =
mc.GetMethodParameters("AddPrinterDriver");
inParams.SetPropertyValue("InfName", "hp4200ps.inf");
// inParams["InfName"] ="hp4200ps.inf";
inParams["DriverName"] = "HP LaserJet 4200 PS";
inParams["SupportedPlatform"] = "x86";
inParams["Version"] = "Windows 2000, Windows XP and Windows Server
2003";
inParams["FilePath"] = @"C:\hp4200ps.inf";
ManagementBaseObject outParams = mc.InvokeMethod("AddPrinterDriver",
inParams, null);
uint retVal = (uint)outParams["ReturnValue"];
Console.WriteLine("Win32_PrinterDriver::Create returned {0}",
outParams["ReturnValue"]);
Any help will be greatly appreciated.
Thanks
ManagementClass mc = new ManagementClass("Win32_PrinterDriver");
ManagementBaseObject inParams = mc.GetMethodParameters("AddPrinterDriver");
ManagementObject driver = new
ManagementClass("Win32_PrinterDriver").CreateInstance();
driver["Name"] = "HP LaserJet 4200 PS";
...
inParams["DriverInfo"] = driver;
ManagementBaseObject outParams = mc.InvokeMethod("AddPrinterDriver",
inParams, null);
...
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<gv> wrote in message news:#92#aSrVDH...@TK2MSFTNGP10.phx.gbl...
"Andy Cheung [MSFT]" <ha...@online.microsoft.com> wrote in message
news:OWmarXtV...@TK2MSFTNGP12.phx.gbl...
--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<gv> wrote in message news:uXQ3HSuV...@TK2MSFTNGP09.phx.gbl...
Thus far, the following has correct parameters (and returns error 5 for not
having the correct privileges).
ManagementClass mc = new ManagementClass("Win32_PrinterDriver");
ManagementObject driver = new
ManagementClass("Win32_PrinterDriver").CreateInstance();
ManagementBaseObject inParams =
mc.GetMethodParameters("AddPrinterDriver");
driver["Name"] = "HP LaserJet 4200 PS";
driver["SupportedPlatform"] = "Windows NT x86";
driver["Version"] = "3";
driver["FilePath"] = @"C:\Driver";
driver["InfName"] = @"C:\Driver\hp4200ps.inf";
driver["Description"] = "HP LaserJet 4200 PS";
inParams["DriverInfo"] = driver;
ManagementBaseObject outParams = mc.InvokeMethod("AddPrinterDriver",
inParams, null);
uint retVal = (uint)outParams["ReturnValue"];
"Andy Cheung [MSFT]" <ha...@online.microsoft.com> wrote in message
news:OwgUhJvV...@tk2msftngp13.phx.gbl...
ConnectionOptions options = new ConnectionOptions();
options.EnablePrivileges = true;
ManagementScope ms = new ManagementScope("\\root\\CIMV2", options);
ms.Connect();
ManagementClass mc = new ManagementClass("Win32_PrinterDriver");
mc.Scope = ms;
ManagementObject driver = new
ManagementClass("Win32_PrinterDriver").CreateInstance();
ManagementBaseObject inParams =
mc.GetMethodParameters("AddPrinterDriver");
driver["Name"] = "HP LaserJet 4200 PS";
driver["SupportedPlatform"] = "Windows NT x86";
driver["Version"] = "3";
driver["FilePath"] = @"C:\Driver";
driver["InfName"] = @"C:\Driver\hp4200ps.inf";
driver["Description"] = "HP LaserJet 4200 PS";
inParams["DriverInfo"] = driver;
ManagementBaseObject outParams = mc.InvokeMethod("AddPrinterDriver",
inParams, null);
uint retVal = (uint)outParams["ReturnValue"];
<gv> wrote in message news:ePVYBi3V...@tk2msftngp13.phx.gbl...