Running SumatraPDF from windows service
I can use Sumatra to print PDF from a windows service but the printer must be installed for the user the service is running as. If the user running the service does not have access to the printer, nothing will print.
To test you may log into the machine and go browse to the printer on the network, double click it to install the printer, now start the Sumatra service again, it will now print.
Dim printer_name As String = $"""{oPick.GetPickPDFPrinterName()}"""
Dim startInfo As System.Diagnostics.ProcessStartInfo = New ProcessStartInfo()
startInfo.FileName = IO.Path.Combine(My.Application.Info.DirectoryPath, "SumatraPDF.exe")
startInfo.Arguments = $"-print-to {printer_name} {FilenameToPrint} -exit-on-print -silent"
startInfo.RedirectStandardError = True
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
startInfo.CreateNoWindow = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden
Using proc As System.Diagnostics.Process = Process.Start(startInfo)
Dim soutput As String = proc.StandardOutput.ReadToEnd()
Dim eoutput As String = proc.StandardError.ReadToEnd()
Dim ReturnCode As Integer = 0
If proc.WaitForExit(15000) Then
If proc.ExitCode = 0 Then
oPick.MarkPickPDFAsPrinted(PickListVersion)
Else
Throw New Exception($"SumatraPDF.exe returned a non-zero return code,…
End If
Else
Debug.Write($"Sending pick PDF to printer possibly failed,SumatraPDF.exe timed out..
End If
End Using