Why LocalPrintServer.GetDefaultPrintQueue () fails on machines in the domain

I have a simple windows service (login: local system) with start / stop as below:

protected override void OnStart(string[] args)
{
    EventLog.WriteEntry(SOURCE, "Start");
    var queue = LocalPrintServer.GetDefaultPrintQueue();
}
protected override void OnStop()
{
    EventLog.WriteEntry(SOURCE, "Stop");
}

      

It works on my local Win 7 (x64) but does not run on Win 7 (x64) on a domain. I see an exception:

The service could not be started. System.Printing.PrintServerException: An exception occurred while getting the default printer. Win32 error: The system cannot find the file specified. at System.Printing.LocalPrintServer.GetDataFromServer (String property, Boolean forceRefresh) at System.Printing.LocalPrintServer.GetUnInitializedData (String [] properties) at System.Printing.LocalPrintServer.get_DefaultPrintQueocalPrint (s) blablabla.Service1.OnStart (String [] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback (State Object)

Can anyone help with this? Thank.

ps I am assuming LocalSystem should have a profile. And I know that my default printer is not the default printer for LocalSystem ...

+3


source to share


1 answer


The local system has no profile ...

I think you have to deal with the lack of a default printer ... And so is the default print queue. In the meantime, there is no need to know about it. ”



http://msdn.microsoft.com/it-it/library/system.printing.localprintserver(v=vs.110).aspx

methods like getprintqueues look interesting for your purpose.

0


source







All Articles