M
Marcel
Hi,
I have a problem using a printer driver with a service running as
local system account.
The program I wrote (look code snippet without error handling below)
first modifies the Printing preferences of a printer and then does a
ShellExecute with "printto" command on that printer. When I run this
program as a user other than system, the file is printed using the new
resolution settings. When I run as system account, every operation
seems to go well, no error codes and the file gets printed, but the
resolution to which it's printed use old settings of the printer.
If any of you has an idea of how I could manage to make the system
account modify the printing preferences and print using these, It
would save me.
Thanks a lot
Marcel
Here is the code snippet:
In the program, I do the following:
// Step 1 - Change printer properties
OpenPrinter("MyPrinterName", &handle, &defaults); // with
PRINTER_ALL_ACCESS
DWORD dwNeeded = 0;
GetPrinter(handle, // handle to printer
2, // information level
NULL, // printer information buffer
0, // size of buffer
&dwNeeded // bytes received or required
);
[...allocated buffer...]
GetPrinter(handle, 2, buffer, dwNeeded, &dwNeeded))
LPDEVMODE pDevMode =
(reinterpret_cast<PRINTER_INFO_2*>(buffer))->pDevMode;
// Change Resolution
pDevMode->dmPrintQuality = 200; //or any value
pDevMode->dmYResolution = 100; //or any value
SetPrinter(handle, 2, buffer, 0))
// Step 2 - Print using printto
SHELLEXECUTEINFO info;
ZeroMemory(&info, sizeof(SHELLEXECUTEINFO) );
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.hwnd = GetDesktopWindow();
info.lpVerb = L"printto";
info.lpFile = path_to_file;
info.lpParameters = L"MyPrinterName WINSPOOL MyPrinterPort";
info.lpDirectory = NULL;
info.nShow = SW_SHOWMINNOACTIVE;
info.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_FLAG_DDEWAIT;
SetLastError(0);
isOk = ShellExecuteEx(&info);
I have a problem using a printer driver with a service running as
local system account.
The program I wrote (look code snippet without error handling below)
first modifies the Printing preferences of a printer and then does a
ShellExecute with "printto" command on that printer. When I run this
program as a user other than system, the file is printed using the new
resolution settings. When I run as system account, every operation
seems to go well, no error codes and the file gets printed, but the
resolution to which it's printed use old settings of the printer.
If any of you has an idea of how I could manage to make the system
account modify the printing preferences and print using these, It
would save me.
Thanks a lot
Marcel
Here is the code snippet:
In the program, I do the following:
// Step 1 - Change printer properties
OpenPrinter("MyPrinterName", &handle, &defaults); // with
PRINTER_ALL_ACCESS
DWORD dwNeeded = 0;
GetPrinter(handle, // handle to printer
2, // information level
NULL, // printer information buffer
0, // size of buffer
&dwNeeded // bytes received or required
);
[...allocated buffer...]
GetPrinter(handle, 2, buffer, dwNeeded, &dwNeeded))
LPDEVMODE pDevMode =
(reinterpret_cast<PRINTER_INFO_2*>(buffer))->pDevMode;
// Change Resolution
pDevMode->dmPrintQuality = 200; //or any value
pDevMode->dmYResolution = 100; //or any value
SetPrinter(handle, 2, buffer, 0))
// Step 2 - Print using printto
SHELLEXECUTEINFO info;
ZeroMemory(&info, sizeof(SHELLEXECUTEINFO) );
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.hwnd = GetDesktopWindow();
info.lpVerb = L"printto";
info.lpFile = path_to_file;
info.lpParameters = L"MyPrinterName WINSPOOL MyPrinterPort";
info.lpDirectory = NULL;
info.nShow = SW_SHOWMINNOACTIVE;
info.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_FLAG_DDEWAIT;
SetLastError(0);
isOk = ShellExecuteEx(&info);