Share via


AddPrinterDriver return error 87

Question

Thursday, January 20, 2011 12:33 PM

I'm tring to add printer driver, but AddPrinterDriver method return error 87

Could You tell me, what's wrong?

My code: 

function iBum
{
 Clear-Host
 $server = read-host "Computer:"
 $dest =”\\$server\c$\Temp\drivers\W32X86\3”
 
 New-Item $dest -type directory -force
 $DestFolder=”\\$server\c$\Temp\drivers\W32X86\3”
 $SrcFolder=”.\drivers\W32X86\3\*”
 Copy-Item $SrcFolder $DestFolder -force
 
 $printerdriverclass =([WMICLASS]"\\$server\ROOT\cimv2:Win32_PrinterDriver")
 $printerdriverclass.psbase.Scope.Options.EnablePrivileges = $true
 $printerdriverclass.psbase.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
  
 $printerdriver = $printerdriverclass.createinstance()
 $printerdriver.Name = "Hp 2055 PCL6"
 $printerdriver.DriverPath = "C:\Temp\drivers\W32X86\3\iakexl.dll"
 $printerdriver.ConfigFile = "C:\Temp\drivers\W32X86\3\iakeuixl.dll"
 $printerdriver.DataFile = "C:\Temp\drivers\W32X86\3\iakexl.dll"
 $printerdriver.HelpFile = "C:\Temp\drivers\W32X86\3\iakehlxl.chm"
 $printerdriver.DependentFiles = "C:\Temp\drivers\W32X86\3\iakercxl.dll", `
  "C:\Temp\drivers\W32X86\3\iakexl.ini", `
  "C:\Temp\drivers\W32X86\3\iakercxl.lrc", `
  "C:\Temp\drivers\W32X86\3\mkmuauth.dll", `
  "C:\Temp\drivers\W32X86\3\mkmuauth.lrc", `
  "C:\Temp\drivers\W32X86\3\mkmxpars.dll", `
  "C:\Temp\drivers\W32X86\3\mkmcodec.dll"
  $rtnCode = $printerdriverclass.AddPrinterDriver($printerdriver)
  $rtncode.returnValue
}

 

 

All replies (13)

Thursday, January 20, 2011 3:10 PM

no clue, I tested sections of it (objects are all correct) and everything seems ok...

what I'd do is run it from the console in admin mode and install to the local machine just to simplify things a bit.

that return wasn’t listed in the docs, but I assume you knew that. pretty weird.. maybe part of the printer driver object you are trying to install doesn’t have something populated that it needs?


Friday, January 21, 2011 6:26 AM

Hi,

 

Based on my research, WMI provider will require 4 attributes on the Win32_PrinterDriver being added

 

Win32_PrinterDriver.Name

Win32_PrinterDriver.SupportPlatform

Win32_PrinterDriver.Filepath

Win32_PrinterDriver.InfName

 

Please unpack the .CAB driver files, then use the above attributes to specify the PrinterDriver.

 

Reference:

 

Problems with WMI and Win32_PrinterDriver

 

Best Regards

Dalea

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”


Friday, January 21, 2011 10:21 AM

hm...

I have added:

$printerdriver.SupportedPlatform = "Windows NT x86"
  $printerdriver.Filepath = "C:\Temp\drivers\W32X86\3\
  $printerdriver.Infname = "C:\Temp\drivers\W32X86\3\iakexl.INF"

but 87 is still occuring...

 

P.s

I have used Microsoft Printer Migrator 3.1 to get all files and informations about driver


Monday, January 24, 2011 3:33 AM

You’re trying to install the printer driver on remote machine, aren’t you? Please copy the driver locally to the remote machine, the install will fail if the driver files are not local to the remote machine.

 

BTW, please try to install the printer locally and see if any error appears.

 

Best Regards

Dale

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”


Monday, January 24, 2011 1:00 PM

he does. he moves them to a temp folder on the C drive.

but, the whole remote thing certain makes it harder to figure out whats going on. I'd try it locally and manually run the commands


Friday, January 28, 2011 7:08 PM

Anyone figure out how to get this script to run remotely? I also get the same return error 87 message when I run it remotely, but works fine locally on the server.


Friday, January 28, 2011 8:31 PM

Anyone figure out how to get this script to run remotely?

Not my...

I have tried to run my script locally (Win7) but 87 error is still occurring

Could this be related to the digital signature of certificate?

 

Edit:

I have found this:

http://support.microsoft.com/kb/229764

Edit 2:

and this:

http://thedailyreviewer.com/xphelp/view/runas-error-87-the-parameter-is-incorrect-1011902231

but I still don't know how to change my script


Friday, January 28, 2011 8:51 PM

Maybe you should specify DependentFiles property as following (with @( and ) because it requires an array):

$printerdriver.DependentFiles = @("C:\Temp\drivers\W32X86\3\iakercxl.dll", `
 "C:\Temp\drivers\W32X86\3\iakexl.ini", `
 "C:\Temp\drivers\W32X86\3\iakercxl.lrc", `
 "C:\Temp\drivers\W32X86\3\mkmuauth.dll", `
 "C:\Temp\drivers\W32X86\3\mkmuauth.lrc", `
 "C:\Temp\drivers\W32X86\3\mkmxpars.dll", `
 "C:\Temp\drivers\W32X86\3\mkmcodec.dll")
?

Friday, January 28, 2011 9:12 PM

no.. :(

still 87


Friday, January 28, 2011 9:59 PM

Could you try to run script locally using the call

$rtnCode = ([WMICLASS]"Win32_PrinterDriver").AddPrinterDriver($printerdriver)

instead of

  $rtnCode = $printerdriverclass.AddPrinterDriver($printerdriver)
I find (somewhere in google) that addPrinterDriver is a static method, so it does not requires an instance of a class.
But I still don't know how it should work in case of a remote system.

Friday, January 28, 2011 10:09 PM

BTW, this script work fine (remotely)

$server = read-host "Comp name"
$PrinterType = "C220"

 $port =([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort")
 $newPort = $port.CreateInstance() 
 $printerdriverclass =([WMICLASS]"\\$server\ROOT\cimv2:Win32_PrinterDriver")
 $printerdriverclass.psbase.Scope.Options.EnablePrivileges = $true
 $printerdriverclass.psbase.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate
 $printerdriver = $printerdriverclass.createinstance()
 
 $print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer")
 $print.psbase.scope.options.enablePrivileges = $true 
 $newprinter = $print.createInstance() 
 
 $printerip=read-host "printer IP"
 $newPort.Name="IP_$printerip"
 $newPort.PortNumber = "9100"
 $newPort.SNMPEnabled=$false
 $newPort.Protocol=1
 $newPort.HostAddress=$printerip
 $newPort.Put()
 
 $dest =”\\$server\c$\Temp\drivers\$PrinterType\x86”
 New-Item $dest -type directory -force
 $DestFolder=”\\$server\c$\Temp\drivers\$PrinterType\x86\”
 $SrcFolder=”.\drivers\$PrinterType\x86\*”
 Copy-Item $SrcFolder $DestFolder -force

 if ([string]::Compare($PrinterType , "c220", $True) -eq 0)
 {
  $printerdriver.Name = "KONICA MINOLTA C360SeriesPCL"
  $printerdriver.Infname = "C:\Temp\drivers\c220\x86\KOAZ8J__.INF"
  $newprinter.DriverName = "KONICA MINOLTA C360SeriesPCL"
  $newprinter.Sharename = "BizhubC220"
  $newprinter.DeviceID = "BizhubC220"
 }
 
 $printerdriver.FilePath = "C:\Temp\drivers\$PrinterType\x86"
 $printerdriverclass.AddPrinterDriver($printerdriver)
 $printerdriverclass.Put()
 
 $newprinter.PortName = $newPort.Name
 $newprinter.Shared = $false 
 $newprinter.Location = ""
 $newprinter.Comment = ""
 
 $newprinter.Put() 
 $newprinter.returnValue
 Pause

 


Friday, January 28, 2011 10:12 PM

Could you try to run script locally using the call

$rtnCode = ([WMICLASS]"Win32_PrinterDriver").AddPrinterDriver($printerdriver)

instead of

  $rtnCode = $printerdriverclass.AddPrinterDriver($printerdriver)
I find (somewhere in google) that addPrinterDriver is a static method, so it does not requires an 

 

87


Sunday, January 30, 2011 2:09 PM

I've had good results using Prnadmin.dll for managing remote printers. It eliminated a lot of headaches for me. There's a good whitepaper called prnadmin.doc in the Windows 2000 resource kit that explains in detail how to use it.

http://support.microsoft.com/kb/321025