PrintDialog中拒绝访问网络打印机

Arm*_*don 7 c# printing wpf

我正在尝试从代码打印到网络打印机,但打印对话框中的网络打印机状态显示Access denied, unable to connect并且打印按钮被禁用.但是如果我从另一个应用程序打印,我可以打印到该打印机.而且,如果我从打印对话框中选择"打印到PDF",那也可以正常工作.我只是无法打印到网络打印机.我有某种权限问题吗?

if (File.Exists(previewDocument))
    File.Delete(previewDocument);

PrintDialog printD = new PrintDialog();
printD.PageRangeSelection = PageRangeSelection.AllPages;
printD.UserPageRangeEnabled = true;

if (printD.ShowDialog() ?? false)
{
    XpsDocument xpsDoc = new XpsDocument(previewDocument, FileAccess.ReadWrite);
    XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
    xpsWriter.Write(((IDocumentPaginatorSource)messageFlow).DocumentPaginator);

    FixedDocumentSequence fixedDocSeq = xpsDoc.GetFixedDocumentSequence();
    printD.PrintDocument(fixedDocSeq.DocumentPaginator, "Hello!");
}
Run Code Online (Sandbox Code Playgroud)

小智 -1

我还不能发表评论,但我想分享我对你的问题的想法。

我在从我的应用程序访问网络驱动器时遇到问题。即使以管理员身份运行。我认为打印机的访问方式类似。

我的问题是用户帐户控制 (UAC)。

尝试根据以下内容设置寄存器:Windows 10 和网络驱动器