Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Printing / Faxing / Scanning > Question about AddPrinter and AddPort...

Reply
Thread Tools Display Modes

Question about AddPrinter and AddPort...

 
 
Robert
Guest
Posts: n/a

 
      04-17-2009
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);
...

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question John Barnett MVP Windows Vista Mail 2 02-05-2009 07:43 AM
Re: Question David B. Windows Vista Mail 0 02-04-2009 07:21 PM
vista genral question and ultimate question pedro g Windows Vista General Discussion 7 02-10-2007 03:34 AM
Dual boot system question and family deal discount question Betatesterzz Windows Vista General Discussion 2 01-31-2007 01:25 PM
Another 32 to 64 bit question Robert Windows Vista General Discussion 1 06-09-2006 02:29 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59