【问题标题】:Printing in a Windows Service在 Windows 服务中打印
【发布时间】:2023-03-13 02:19:01
【问题描述】:

我正在尝试在 Windows 服务中打印。使用以下VB.Net代码:

    Dim _pd As New System.Drawing.Printing.PrintDocument()

    AddHandler _pd.PrintPage, New System.Drawing.Printing.PrintPageEventHandler(AddressOf PrintDocument_PrintPage)
    AddHandler _pd.EndPrint, New System.Drawing.Printing.PrintEventHandler(AddressOf PrintDocument_EndPrint)

    _pd.Print()

EventHandlers 被实现和测试。当我运行代码(使用 AccountType:User)时,我收到一个异常消息,即“未安装打印机”。在 Windows 窗体应用程序中,一切正常。

我正在使用网络打印机。

提前谢谢你, 亚历山大

【问题讨论】:

  • 服务运行的帐户是否设置了任何打印机?
  • Windows 窗体应用程序,代码在其中运行,在与服务相同的帐户上运行(我的机器上只安装了一个用户)。
  • 是本地安装的打印机,还是网络打印机
  • 我使用的是网络打印机,但它是通过本地“安装打印机向导”安装的,并且在我的 Windows 窗体应用程序中运行良好。
  • @alxppp 如果我可以问,你有没有计时器?你用的是什么定时器?

标签: windows vb.net printing service


【解决方案1】:

不建议在 Windows 服务中打印。

您需要为您的服务(域帐户)使用different account,以便您可以访问网络资源。

您可以在以下位置找到更多信息:Network printing with window service

【讨论】:

    【解决方案2】:

    试试这个代码,它可以让你打印任何东西:

    Dim psi As New ProcessStartInfo
    psi.UseShellExecute = True
    psi.Verb = "print"
    psi.WindowStyle = ProcessWindowStyle.Hidden
    psi.FileName = sReport
    Process.Start(psi)
    

    【讨论】:

      【解决方案3】:

      您可以借助 Windows API 通过 Windows 服务进行打印。 System.Drawing.Printing 不能很好地配合服务。

      查看此链接:http://support.microsoft.com/kb/322090

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-09
        相关资源
        最近更新 更多