Microsoft Windows Vista Community Forums - Vistaheads
Recommended Download



Welcome to the Microsoft Windows Vista Community Forums - Vistaheads, YOUR Largest Resource for Windows Vista related information.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so , join our community today!

If you have any problems with the registration process or your account login, please contact us.

Driver Scanner

Question about AddPrinter and AddPort...

microsoft.public.windows.vista.print fax scan






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

Posts: n/a
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);
...

Reply With Quote
Sponsored Links
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

vB 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 bibz1 microsoft.public.windows.vista.mail 0 08-27-2008 01:37
AMD question phionex microsoft.public.windows.vista hardware devices 1 02-01-2008 23:19
vista genral question and ultimate question =?Utf-8?B?cGVkcm8gZw==?= microsoft.public.windows.vista.general 7 03-01-2007 12:06
One more question.. Bucko21 microsoft.public.windows.vista.general 2 03-01-2007 03:50
Dual boot system question and family deal discount question =?Utf-8?B?QmV0YXRlc3Rlcnp6?= microsoft.public.windows.vista.general 4 03-01-2007 03:42




All times are GMT +1. The time now is 09:21.




Driver Scanner - Free Scan Now

Vistaheads.com is part of the Heads Network. See also XPHeads.com , Win7Heads.com and Win8Heads.com.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.0 RC 2

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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120