View Single Post
 
Old July 27th, 2003, 11:30 PM
mbarrett mbarrett is offline
Registered User
 
Join Date: Jul 2003
Location: Lafayette, in, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unhandled Exception:

How do you handle this exception?

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. at System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode) at System.Management.ManagementScope.InitializeGuts()

The try/catch block in the following code fragment should handle the above exception but does not. Why?

string[] systems = {"cpu1", "cpu2", "OnLine-
    NotResponding", "off-line"};
ConnectionOptions wmiConnOption;
ManagementObjectSearcher osSearch;
ManagementObjectCollection osInfo;
ManagementScope scope;
ObjectQuery osQuery;
wmiConnOption = new ConnectionOptions();
wmiConnOption.Impersonation = ImpersonationLevel.Impersonate;
osQuery = new ObjectQuery("Select * from Win32_OperatingSystem");
for (int i = 0; i < systems.Length; i++)
{
   scope = new ManagementScope("\\\\" + systems[i] + "\\root\\cimv2",
      wmiConnOption);
   osSearch = new ManagementObjectSearcher(scope, osQuery);
   try
   {
       scope.Connect();
   }
   catch(Exception e)
   {
       Console.WriteLine("Access error: " + e.Source);
   }
   if(scope.IsConnected)
   {
       osInfo = osSearch.Get();
       foreach(ManagementObject osItem in osInfo)
       {
          Console.WriteLine(systems[i] + " OS Version: " + osItem
             ["Version"]);
       }
   }
}

The security context is administrator for the code
and access to the remote systems. For systems "cpu1" & "cpu2" the
code works as expected. System "OnLine-NotResponding" can be
pinged but does not responding to remote access. System "Off-line"
is off-line or may not exist.

The last two systems in the array throw the "Unhandled Exception".

Thanks,
Mike