2

Я попытался распечатать файл PDF из моей службы windows. Это не работало. Later я написал консольное приложение для печати PDF-файла. Консольное приложение действительно сработало! приложение из сервиса, чтобы распечатать файл pdf, он не работал. Почему эта «печать» не работает с сервисом Windows? нижеследующие фрагменты кода, которые я пробовалКак распечатать pdf-файл с помощью службы Windows

1.Used adobe reader: 
       PdfReportGeneration.Log logs = new PdfReportGeneration.Log(); 
       logs.writeLog("PrintDocument filepath:-" + filepath); 

       Process process = new Process(); 
       process.StartInfo.FileName = filepath; 
       process.StartInfo.UseShellExecute = true; 
       process.StartInfo.Verb = "printTo"; 
       process.StartInfo.Arguments = "HP LaserJet P1005"; 
       process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
       process.Start(); 
       process.WaitForInputIdle(); 
       process.Kill(); 

2. Used foxit reader/adobe reader both didnt work 
    string sArgs = " /t \"" + filepath + "\" \"" + "HP LaserJet P1005" + "\""; 
    System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo(); 
    startInfo.FileName = @"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"; 
    startInfo.Verb = "printTo"; 
    startInfo.Arguments = sArgs; 
    startInfo.CreateNoWindow = true; 
    startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
    System.Diagnostics.Process proc = Process.Start(startInfo); 
    proc.WaitForExit(100000); // Wait a maximum of 10 sec for the process to finish 
    if (!proc.HasExited) 
    { 
     proc.Kill(); 
     proc.Dispose(); 
     // return false; 
    }*/ 

Сделано много Google Bing yahoo .. не использовать !!

ответ

1

Служба обычно управляется другой учетной записью. Я бы попытался запустить службу как пользователь. Может быть проблема, что системный пользователь не отобразил этот принтер. Класс установки службы будет выглядеть так:

[RunInstaller(true)] 
public class ServiceInstall : Installer 
{ 
    public ServiceInstall() 
    { 
     ServiceInstaller serviceInstaller = new ServiceInstaller(); 
     ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller(); 

     serviceProcessInstaller.Account = ServiceAccount.User; 
     serviceProcessInstaller.Username = "User"; 
     serviceProcessInstaller.Password = "Password"; 

     serviceInstaller.DisplayName = "Some Service"; 
     serviceInstaller.StartType = ServiceStartMode.Automatic; 
     serviceInstaller.ServiceName = "Some Service"; 

     this.Installers.Add(serviceProcessInstaller); 
     this.Installers.Add(serviceInstaller); 
    } 
} 
+0

Что такое serviceProcessInstaller здесь? – flute

+0

и Nope он не работал :-(попробовал в качестве администратора! – flute

+0

В качестве следующего шага я попытался бы позволить этому процессу иметь собственное окно. Возможно, вы можете найти там, что происходит в этом процессе. –

Смежные вопросы