WritePrinter doesn't work with "FILE:" Port.  
Author Message
Automata





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Hi all!!!

I made following code and compiled it with 2003SDKSP1.

In order to test in VISTA RC2, I changed the port from USB001 to FILE: in printers properties.

But It showed error message like "Error - Printing" after running.

Actually, It works well with 9x,2k and XP.

Any help would be appreciated

Thanks,
JMH

HANDLE hPrinter = 0;
DWORD dwBytesWritten=0;
CString strDocName;
DWORD dwFileLength = 0;
char szData[512];

strcpy(szData,"TEST TEST TEST TEST TEST");

if (OpenPrinter(szPrinterName, &hPrinter, NULL)) {

DOC_INFO_1 DocInfo;

DocInfo.pDocName = "TEST";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = _T("RAW");

if (StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)) {
if (StartPagePrinter(hPrinter)) {
BOOL bRet = WritePrinter(hPrinter, (void*)szData, strlen(szData) , &dwBytesWritten);

EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}

}



Software Development for Windows Vista7  
 
 
Matthew Braun - MSFT





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Hello Automata,

Have you tried any compatibility shims on your application such as XP SP2, also do you experience the same results if you elevate your application Could you also try running the Standard User Analyzer tool on your application, SUA can be downloaded from http://www.microsoft.com/downloads/details.aspx FamilyID=DF59B474-C0B7-4422-8C70-B0D9D3D2F575&displaylang=en and post the report back on the forums Also is your application a standalone win32 exe or is it running under a win32 service context

Thanks!

Matthew Braun



 
 
Automata





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

I checked my test application with SUA.

It showed the following error message.

Detailed Information:
CreateFileW: File (\Device\HarddiskVolume1\Windows\System32\spool\PRINTERS\00002.SPL) only grants requested 'FILE_WRITE_DATA' to 'BUILTIN\Administrators, NT AUTHORITY\SYSTEM'

StopCode: 0x331B
Severity: Error
Message: Access was restricted to trusted users only.

Stack Trace:

vfluapriv2!DllUnregisterServer+298d
vfluapriv2!DllUnregisterServer+2ede
vfluapriv2!DllUnregisterServer+307e
vfluapriv2!DllUnregisterServer+3141
vfluapriv2!DllUnregisterServer+31d1
vfluapriv2!DllUnregisterServer+3300
vfluapriv2!DllUnregisterServer+65dd
WINSPOOL!StartDocPrinterW+171
WINSPOOL!StartDocPrinterA+49
VISTATEST!+401c6c
VISTATEST!+47a534
VISTATEST!+47ac61
VISTATEST!+47b991
VISTATEST!+48094b
VISTATEST!+47fb61
VISTATEST!+47fae4
VISTATEST!+47d689
VISTATEST!+47db25
USER32!GetMessageW+9d
USER32!SetWindowLongW+d1
USER32!GetMessageW+63f
USER32!SendMessageW+49
USER32!DrawFrame+503
USER32!DrawFrame+4bc
USER32!DrawFrame+4af
USER32!GetClipboardData+155
USER32!GetMessageW+9d
USER32!SetWindowLongW+d1
USER32!IsWindow+14e
USER32!DispatchMessageW+f
USER32!IsDialogMessageW+eb
USER32!IsDialogMessage+4a
VISTATEST!+484275
VISTATEST!+482e64
VISTATEST!+47b964
VISTATEST!+481a30
VISTATEST!+479c75
VISTATEST!+47a0dc
VISTATEST!+48306f

The printer has full permissions. login account is member of Administrators group.

My vista version is RC2 5744.

There is no error with I/O like USB & Parallel port.

What is problem

Thanks

JMH - Automata


 
 
Matthew Braun - MSFT





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Hi Automata,

You must elevate your appliation to run in an Administrator context, even though your user is a member of the Administrators group you are still running in a standard user context. I would take the following actions to see if this corrects your issue:

  1. Right click on your exe -> Run as Administrator
  2. Attempt to duplicate the issue
  3. If the issue is fixed I would suggest manifesting the assembly of your appliation with a requiresElevation

I have written about manifesting your appliations in my blog here. I also make reference to Chris Jacksons blog for the proper manifest schema so check that out as well.

Let me know if this works or not.

Thanks!

Matthew Braun



 
 
Oliver Lundt - MSFT





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Is this a Kernel mode Printer driver  All printer drivers will now have to follow the User mode driver framework. All kernel mode printer drivers will be blocked from loading on Windows Vista. For more information, see the User Mode Driver Framework (UMDF) site. http://www.microsoft.com/whdc/driver/wdf/UMDF.mspx 



 
 
Automata





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Hi Matthew Braun

 

I checked my test program with "Run as Administrator" in VISTA RTM version.

The issue is reproduced. Printer Driver is "Dell Laser MFP 1815"

But Notepad works properly. I don't think that application uses "WritePrinter" fuction. :)

Thanks for your help.

 

JMH - Automata


 
 
Curt007





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

I am having the same problem.

I also tried the Vista compatible HP print driver at :

http://h20338.www2.hp.com/Hpsub/cache/343033-0-0-225-121.html

which should be a users mode print driver rather then a 'Kernel mode Print driver'

I was able to get past the 'FILE_WRITE_DATA' error as noted in a previous post by adding promissions to the \Windows\System32\spool\PRINTERS folder.

But, now I'm stuck with this error when running the SUA

OpenProcess: Process (pid 0x00000c60) only grants requested 'PROCESS_DUP_HANDLE' to 'BUILTIN\Administrators, NT AUTHORITY\SYSTEM'

I think the problem is that it fails to open the prompt for a filename.


 
 
k9gatton





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

OpenPrinter takes a third argument that can elevate security.

Try this:

PRINTER_DEFAULTS prDefaults;

prDefaults.pDatatype = 0;

prDefaults.pDevMode = 0;

prDefaults.DesiredAccess = PRINTER_ALL_ACCESS; //Grants Administrator access.

HANDLE hPrinter = 0;

OpenPrinter(prName,&hPrinter,&prDefaults);

This might fix the issue.

Sincerely,

Kurt



 
 
Curt007





PostPosted: Application Compatibility for Windows Vista, WritePrinter doesn't work with "FILE:" Port. Top

Good idea,

I tried it, but it didn't work. Thanks for the idea.