What causes System.Drawing.Printing.PrinterSettings.InstalledPrinters to throw Win32Exception “RPC server not available”?

夙愿已清 提交于 2020-01-01 11:34:12

问题


I have an application that I'm working on and I allow the user to select a printer to use as their printer while printing forms from the application. I'm using .NET 2.0

In the settings screen, I call

System.Drawing.Printing.PrinterSettings.InstalledPrinters 

to get the list of available printers.

On a client's machine, the property throws an exception:

System.ComponentModel.Win32Exception: The RPC server is unavailable

The client is reporting that windows shows his printer as 'ready', and the client can print test pages from the printer. But, I have not been able to reproduce this issue locally and I'm running out of ideas. Does anyone have any ideas what could cause this issue? Any ideas or directions to look would be helpful. Thanks


回答1:


If you can print, most likely a security issue. Otherwise I would have voted "dead spooler service" but more likely your app doesn't have the rights to communicate with the spooler service...




回答2:


This same thing is happening to me in Windows 7. Stopping and starting the print spooler in services fixes until it happens again.

The following commands make it quick to do this:

net stop "print spooler"
net start "print spooler"

Note: Run the command prompt as Admin. I made a batch file to do this because it happens 4-5 times a day during development.




回答3:


Either the RPC service is off or Windows Firewall is blocking it.




回答4:


I had a similar problem using PrinterSettings.InstalledPrinters and the cause was that the application was running with "Partial Trust" permissions.

In Visual Studio, went to Project Properties\Security and selected "This is a full trust application".

I'm not sure if this is going to help you but did it for me.




回答5:


Could this have anything to do with Network Printers? RPC is Remote Procedure Call, perhaps this is used for detecting installed network-printers?

After some googling on the error:

The InstalledPrinters uses WMI to look for printers. WMI on its turn uses RPC.

Having WMI return an error of your kind could mean the following:

  • MSDN Support
  • It could have something to do with accounts: check local/network/system account for your application and try running your application under a registered account (user+password)
  • Also check forum post, solving this for an ASP.NET application: link

And a useful WMI resource for your problem.




回答6:


Another possibility is also that the PrintSpooler service has been set to Disabled



来源:https://stackoverflow.com/questions/734628/what-causes-system-drawing-printing-printersettings-installedprinters-to-throw-w

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!