Answered System.Management generic failure

  • Wednesday, October 31, 2007 10:23 PM
     
     

    Part of a program that runs on thousands of machines attempts to list the current interactive users on the machine using this snippet:

     

     

                    string interactiveUsers = string.Empty;

                    ManagementScope ms = new ManagementScope(ManagementPath.DefaultPath);
                    System.Management.ManagementObject o;
                    SelectQuery q = new SelectQuery("Win32_LoggedOnUser"); // Only interactive logons.
                    ManagementObjectSearcher query = new ManagementObjectSearcher(ms, q);

                    ManagementObjectCollection queryCollection = query.Get();

                    foreach (ManagementObject mo in queryCollection)
                    {
                        o = new ManagementObject(mo["Dependent"].ToString());
                        if ((o["LogonType"].ToString()) == "2")
                        {// Is interactive?
                            interactiveUsers += "LogonID = " + o["LogonID"].ToString() + ", ";
                            o = new ManagementObject(mo["Antecedent"].ToString());
                            interactiveUsers += "Caption = " + o["Caption"].ToString() + ", Description = " +
                                o["Description"].ToString() + ", SID = " + o["SID"].ToString() + "; ";
                        }

         }

     

     

    This works as expected the majority of the time, but a small percentage of the time I get:

     

    System.Management.ManagementException: Generic failure
       at System.Management.ManagementScope.Initialize()
       at System.Management.ManagementObjectSearcher.Initialize()
       at System.Management.ManagementObjectSearcher.Get()


     

    Anybody know what this means in English, and how I can keep it from happening? I have other uses in mind for WMI, but not if it fails at random without a meaningful message.

All Replies

  • Thursday, November 01, 2007 10:53 PM
     
     

    I'm going to "answer" my own question here. Having done more research, WMI appears rather hugely complicated. I modified my code so that if I get such an exception, I silently run the handy WMIDiag utility (http://www.microsoft.com/technet/scriptcenter/topics/help/wmidiag.mspx) to check the state of WMI on the system and store the results for review. It coughed up a bunch of errors like:

     

    .1764 14:18:30 (0) ** - Root, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1765 14:18:30 (0) ** - Root, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1766 14:18:30 (0) ** - Root/Default, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1767 14:18:30 (0) ** - Root/CIMv2, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1768 14:18:30 (0) ** - Root/WMI, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1769 14:18:30 (0) ** - root/ccm/Messaging, 0x80041001 - (WBEM_E_FAILED) Call failed.
    .1770 14:18:30 (0) ** - root/ccm/ContentTransferManager, 0x80041001 - (WBEM_E_FAILED) Call failed.

    Turns out I have a bunch of systems of a particular model that have problems with their WMI infrastructure. Probably a bad image for those machines since it's limited to a specific model. But, since I have no control over reconfiguring those machines, I'm going to avoid using WMI calls. It's a shame since there is so much info available, but since I can't guarantee that WMI will function correctly on a given machine, I can't rely on it in this situation.

     

  • Friday, November 02, 2007 5:53 AM
    Moderator
     
     Answered

    Hi Peter,

     

    I did some research from the websites and found a thread with the same exception message as yours here. For your issues, try to check if the WMI service is running (possibly it stopped/crashed/etc) when the "System.Management.ManagementException: Generic failure" happens. 

    For the error "x80041001- Generic Failure", I recommend you checking out this KB article for reference - http://support.microsoft.com/kb/823442

     

    Hope this helps,

    Regards,