Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroups > Vista print fax & scan

Vista - Question about AddPrinter and AddPort...

Reply
 
Old 04-17-2009   #1 (permalink)
Robert


 
 

Question about AddPrinter and AddPort...

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);
...


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
escape character question - hopefully an easy question PowerShell
Question Vista mail
vista genral question and ultimate question Vista General
Dual boot system question and family deal discount question Vista General
RC1 Cd Key Question Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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