c# - ManagementException: Generic failure accessing Win32_Printer (resulting in RPC server is unavailable) -


this exception started occurring had on server2003 , 2008r2:

managementexception: generic failure stack:    @ system.management.managementexception.throwwithextendedinfo(managementstatus errorcode)   @ system.management.managementobjectcollection.managementobjectenumerator.movenext() 

after receiving error i've seen exception occuring (spooler stopped?):

the rpc server unavailable  win32exception: rpc server unavailable stack:    @ system.drawing.printing.printersettings.get_installedprinters() 

the code generates wmi query listed here:

// printername:   \\server\printer  or   mylocalprinter  printerattributes attribs = printerattributes.hidden; managementobjectsearcher searchprinter = null; managementobjectcollection prntcol = null;  try  {     // "select attributes, name win32_printer"     string qry = string.format("select attributes, name win32_printer name = \'{0}\'", printername);     searchprinter = new managementobjectsearcher(qry);     prntcol = searchprinter.get();      foreach (managementobject prnt in prntcol) {       if (prnt["name"].tostring() == printername) { /* ... */ }     } }  {     if (prntcol != null) prntcol.dispose();     if (searchprinter != null) searchprinter.dispose(); }  // ... 

after doing search i've found these links give me possible hint:

  1. https://stackoverflow.com/a/5247725/187650
  2. http://social.msdn.microsoft.com/forums/vstudio/en-us/b20c35f7-375b-4b67-af2e-bd432b6915da/how-to-retrieve-all-printer-names-installed-in-a-pc
  3. http://www.tech-archive.net/archive/development/microsoft.public.win32.programmer.wmi/2005-12/msg00097.html
  4. http://www.vistax64.com/powershell/134250-get-wmiobject-generic-failure.html

even when try in powershell query remote pc:

get-wmiobject -query "select attributes, name win32_printer" -computername "remotepc" 

i receive error after while:

get-wmiobject : rpc server unavailable. (exception hresult: 0x800706ba) @ line:1 char:1 + get-wmiobject -query "select name win32_printer" -computername "remotepc" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : invalidoperation: (:) [get-wmiobject], comexception     + fullyqualifiederrorid : getwmicomexception,microsoft.powershell.commands.getwmiobjectcommand 

are there wmi experts share improvements on piece of c# code, because @ moment have no clue why happens once in while.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -