ManagementException: general failure while accessing Win32_Printer (causing the RPC server to be unavailable)

This is an exception that recently appeared on server 2003 and 2008r2:

ManagementException: Generic failure Stack: at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() 

After receiving this error, I also saw this exception (spooler stopped?):

 The RPC server is unavailable Win32Exception: The RPC server is unavailable Stack: at System.Drawing.Printing.PrinterSettings.get_InstalledPrinters() 

The following is the code that generates the WMI request:

 // printername: \\server\printer or mylocalprinter PrinterAttributes attribs = PrinterAttributes.Hidden; ManagementObjectSearcher searchPrinter = null; ManagementObjectCollection prntCol = null; try { // "SELECT Attributes, Name FROM Win32_Printer" string qry = string.Format("SELECT Attributes, Name FROM Win32_Printer WHERE Name = \'{0}\'", printerName); searchPrinter = new ManagementObjectSearcher(qry); prntCol = searchPrinter.Get(); foreach (ManagementObject prnt in prntCol) { if (prnt["Name"].ToString() == printerName) { /* ... */ } } } finally { if (prntCol != null) prntCol.Dispose(); if (searchPrinter != null) searchPrinter.Dispose(); } // ... 

After doing a search, I found these links to give me a possible hint:

Even when I try in PowerShell to execute this request for a remote PC:

 Get-WmiObject -Query "SELECT Attributes, Name FROM Win32_Printer" -ComputerName "remotepc" 

I get this error after a while:

 Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:1 char:1 + Get-WmiObject -Query "SELECT Name FROM Win32_Printer" -ComputerName "remotepc" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand 

Are there any WMI experts who could share the improvements on a piece of C # code, because at the moment I don’t know why this happens only once in a while.

+4
source share

Source: https://habr.com/ru/post/1499333/


All Articles