I have an executable that installs a printer driver, and then creates a printer using said driver. I use a tlbimp generated managed version of prnadmin from the server 2003 resource kit.
On windows XP, I have to set the print processor to MS_XPS. The default processor is WINPRINT. This snippet is what does that.
static string winxpPrinterProcessor = "MS_XPS";
if (isWinXP() && pPrinter.PrintProcessor != winxpPrinterProcessor)
{
Console.WriteLine("Oh No, the printer exists, but the processor isn't XPS. Setting now. It's currently " + pPrinter.PrintProcessor);
pPrinter.PrintProcessor = winxpPrinterProcessor;
Console.WriteLine("Set the processor to " + winxpPrinterProcessor);
if (updateOnly)
{
pMaster.PrinterSet(pPrinter);
} else { //else we're adding
pMaster.PrinterAdd(pPrinter);
}
When running the program myself, by double clicking, it works perfectly. When running it as a MSI Custom Action, it doesn’t work. Everything works (installing the printer, driver, setting the port) but setting the print processor. Windows just ignores the processor setting.
The MSI launches the custom action (it’s a console app) process as the SYSTEM user. When I manually launch it it’s running under my Domain Admin account.
I should also note that installing the printer manually works fine as well because xp picks up the processor from the INF file. It ignores that setting when using the prnadmin dll.
I’ve had a very frustrating morning. Any thoughts? Or better ways to install a printer?
Okay, never figured out why it failed in that specific case, but I did figure out a much better work around. If somebody can answer my original question I’ll give you the answer.
background: we chose to do everything with the prnadmin wrapper because we had to create a port and that seemed the easiest way to do that.
Instead of creating the printer with managed code as well we now shell out commands to PrintUI. We can set the port with PrintUI and windows XP will pick up the processor specified in the INF file when using PrintUI, so it kills 2 birds with one stone.