I'm trying to use the OpenPrinter function to obtain a handle as such with the appropriate initialization before calling the function:
Code:
HANDLE printerHandle = INVALID_HANDLE_VALUE;
// initialize PRINTER_DEFAULT structure being obtaining printer handle
// as mentioned in MSDN shown in http://msdn.microsoft.com/en-us/library/ms536027.aspx
PRINTER_DEFAULTS pd_settings;
pd_settings.pDatatype = NULL;
pd_settings.pDevMode = NULL;
// set DesiredAccess to perform adminstrative tasks (i.e. permissions as indicated
// in the MSDN documentation on PRINTER_DEFAULTS structure
pd_settings.DesiredAccess = PRINTER_ALL_ACCESS;
if (!OpenPrinter(TEXT(",XcvMonitor Local Port"),
&printerHandle, // phPrinter == printer handle received
&pd_settings // pDefault == information about administrative rights
))
{
wcout << "Error Code = " << GetLastError() << endl;
return FALSE;
}
However, I keep on getting an error saying I don't have the administrative rights even though the user is a computer admin on Windows operating system and I've set the permission settings in my code. I'm not what I'm misusing or missing. Any feedback would be helpful. Thanks.