Question about AddPrinter and AddPort...

R

Robert

Hello,

I am hoping someone can shed some light on either of these two issues.

In one case, when a logged into a VM as a Power User I cannot use the win32
AddPrinter API call to create a copy of the printer. It fails with error 1307
(This security ID may not be assigned as the owner of this object.) The user
does have load/unload device driver privs as I added the power users group to
the policy. The printer was initially installed under the local administrator
account. What is puzzling is that I can add copies of the printer using the
Add Printer Wizard. My tests were all done on Windows XP in this case.

The second problem involves creating local ports when logged in remotely.
Our COM object creates "cloned" copies of a printer. Each of the cloned
copies is on a separate local port . We create these using the
OpenPrinter(L",XcvMonitor Local Port", &hXVCPrinter, &PrinterDefaults) call
with PrinterDefaults set to SERVER_ACCESS_ADMINISTER, followed by a call to
XcvData(hXVCPrinter, L"AddPort", (BYTE *)PortName, (lstrlenW(PortName) + 1) *
2, NULL, 0, &dwNeeded, &dwStatus) to create the port. The second call fails
with ACCESS_DENIED, but if I add a port through the Printers and Faxes, it is
added successfully.
I am logged in remotely as administrator on a Vista-64 SP1 machine, and
running a C# sample that uses the COM object when this happens.

Code for AddPrinter:

HANDLE hPrinterOld = NULL ;
PRINTER_INFO_2 *pPrinterOldInfo = NULL;
HANDLE hPrinter = NULL ;
PRINTER_INFO_2 PrinterInfo ;
DWORD dwError = ERROR_SUCCESS ;

PRINTER_DEFAULTS pd ;
HANDLE hPrinterOld = NULL ;
DWORD dwError = 0 ;


memset( &pd, 0, sizeof(pd) ) ;
pd.DesiredAccess = PRINTER_READ; //PRINTER_ALL_ACCESS ;

if ( OpenPrinter( (LPTSTR)pszOldPrinterName, &hPrinterOld, &pd ) )
{
pPrinterOldInfo = ( PRINTER_INFO_2 *)MyGetPrinter( hPrinterOld, 2 ) ;
ClosePrinter( hPrinterOld ) ;

if ( pPrinterOldInfo == NULL ) {
dwError = GetLastError() ;
return dwError ;
}
}
else
{
dwError = GetLastError() ;
return dwError ;
}

memset( &PrinterInfo, 0, sizeof(PrinterInfo) ) ;

PrinterInfo.pPrinterName = (LPTSTR)pszNewPrinterName ; //szPrinterName ;
PrinterInfo.pPortName = pPrinterOldInfo->pPortName ;
PrinterInfo.pDriverName = pPrinterOldInfo->pDriverName ;
PrinterInfo.pComment = pPrinterOldInfo->pComment ;
PrinterInfo.pLocation = pPrinterOldInfo->pLocation ;
PrinterInfo.pDevMode = pPrinterOldInfo->pDevMode ;
PrinterInfo.pPrintProcessor = pPrinterOldInfo->pPrintProcessor ;
PrinterInfo.pDatatype = pPrinterOldInfo->pDatatype ;
PrinterInfo.pParameters= pPrinterOldInfo->pParameters ;
PrinterInfo.pSecurityDescriptor = pPrinterOldInfo->pSecurityDescriptor ;
PrinterInfo.Attributes = pPrinterOldInfo->Attributes ;
PrinterInfo.Priority = pPrinterOldInfo->Priority ;
PrinterInfo.DefaultPriority = pPrinterOldInfo->DefaultPriority ;
PrinterInfo.pSepFile = pPrinterOldInfo->pSepFile ;

hPrinter = AddPrinter (NULL, 2, (LPBYTE) &PrinterInfo ) ;
if ( ! hPrinter )
{
....


Code for Port Creation:

HRESULT hr = S_OK ;
DWORD dwNeeded, dwStatus, dwError ;
WCHAR PortName[1024];
BOOL bSucceeded = FALSE ;
HANDLE hXVCPrinter = NULL ;
CString szPortPath = _T("") ;

PRINTER_DEFAULTS PrinterDefaults;

PrinterDefaults.pDatatype = NULL;
PrinterDefaults.pDevMode = NULL;
PrinterDefaults.DesiredAccess = SERVER_ACCESS_ADMINISTER;

if (OpenPrinter(L",XcvMonitor Local Port", &hXVCPrinter, &PrinterDefaults))
{
lstrcpyW(PortName, (LPTSTR)(LPCTSTR)this->m_szPrinterPortName );

dwError = ERROR_SUCCESS;
bSucceeded = XcvData(hXVCPrinter, L"DeletePort", (BYTE *)PortName,
(lstrlenW(PortName) + 1) * 2, NULL, 0, &dwNeeded, &dwStatus);
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top