QuickReport throws "There Is No Default Printer Currently Selected" Exception

23,284

Solution 1

You can solve this problem by creating a new dword UserSelectedDefault with the value: 1 in HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\Session_ID

Make sure you have a local printer selected.

Solution 2

Is there a default printer set up in session 0? Remember that under Vista / Server 2008 / Windows 7, services run in a separate session. Whether or not the logged-in user has a default printer set is not relevant - it's a per-session setting and doesn't affect session 0.

Can you rewrite the code to gracefully handle that exception and pick a printer to use?

Solution 3

A colleague ended up finding the solution. I should have added these are "network" printers and not Local printers (at the time I didn't think this was related to the problem). So the service needed to be installed with "NetworkService" as the user account under the logon tab. From the Windows Help:

To specify that the service uses the Network Service account, click This account, and then type NT AUTHORITY\NetworkService

Solution 4

Actually it is a Delphi(5) problem. The comparison of the available printers and the default printer is case sensitive (Printers.pas):

if TPrinterDevice(Objects[I]).Device = Device then
begin
   with TPrinterDevice(Objects[I]) do
      SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
   Exit;
end;

Changing the comparison to: if lowercase(TPrinterDevice(Objects[I]).Device) = lowercase(Device) solves the problem.

Solution 5

We had a simular problem here. Using TS servers, Citrix and Powerfuse 9. Powerfuse had all printers capitalized, however they were shared in a mixed case. This combination caused Delphi/QReport to crash

When all printers are from printserver to powerfuse in the same case (not important upper or lower or even mixed), the problem was gone

Share:
23,284
M Schenkel
Author by

M Schenkel

I program predominantly in Delphi.

Updated on February 28, 2020

Comments

  • M Schenkel
    M Schenkel about 4 years

    I have created a Delphi Service which prints TQuickReports. Everything works fine if compiled and run as a Windows Application. But when converted to operate as a service trying to create a form containing a TQuickRep component throws the exception.

    This service runs fine on many other boxes but not this one in particular. Here are some details:

    • Using QuickReport version 4.07
    • Box is a Windows Server 2008 operating system.
    • Using Delphi 2007
    • Printer.Printers.Count is returning a positive value. In fact I can list out all of the printers.
    • I have tried running the service both using Local System Account and Logged on as an Admin.
  • M Schenkel
    M Schenkel about 14 years
    In fact this is EXACTLY what we do. Essentially the printer is specified by name and then we have a routine which will scan the Printer.Printers array and return the integer. Problem is I can't even get to this point; I can't even create a TQuickRep instance.
  • M Schenkel
    M Schenkel about 14 years
    This is new to me. No, I was not aware there were "sessions". How do I get a handle to a specific "Session"?
  • Marcus Adams
    Marcus Adams about 14 years
    @M Schenkel, seems like a bug, but the work around is probably to set the default printer prior to creating your TQuickRep object.
  • krasnoperov
    krasnoperov about 14 years
    Can you post the code around where the error happens? We have implemented a variation on the solution suggested by Marcus Adams for printing Quick Report reports via a Windows Service and do not see the error that you do on Windows 2008.
  • M Schenkel
    M Schenkel about 12 years
    I think the other answer solved the problem. But will keep this in mind.
  • M Schenkel
    M Schenkel almost 12 years
    Having a local printer (even though there was not physically one attached) resolved issue.