none
System.Management.ManagementException was unhandled by user code HResult=-2146233087 Message=Generic failure RRS feed

  • Question

  • Hi All,

    I'm getting below error when i try to run a method remotely. Please help.

    Error :

    System.Management.ManagementException was unhandled by user code
      HResult=-2146233087
      Message=Generic failure 
      Source=System.Management
      StackTrace:
           at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
           at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
           at _Default.btnsave_Click(Object sender, EventArgs e) in e:\Jay_ScriptTest\Sample\Default.aspx.cs:line 92
           at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
           at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException: 

    Code :

            WqlConnectionManager connection = new WqlConnectionManager();
            ConnectionOptions options = new ConnectionOptions();
            options.Impersonation = System.Management.ImpersonationLevel.Impersonate;

            ManagementScope scope = new ManagementScope("\\\\XXXXXXX\\root\\sms\\site_cas");
            scope.Connect();

            String query1 = "Select resourceid,netbiosname from sms_r_system where name='" + txtname.Text + "'";
            String query2 = "Select resourceid,netbiosname,smbiosguid from sms_r_system where smbiosguid='" + txtuuid.Text + "'";
            ObjectQuery queryn = new ObjectQuery(query1);
            ObjectQuery queryu = new ObjectQuery(query2);
            ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, queryn);
            ManagementObjectSearcher searcher2 = new ManagementObjectSearcher(scope, queryu);
            ManagementObjectCollection querycollection1 = searcher1.Get();
            ManagementObjectCollection querycollection2 = searcher2.Get();
            if ((querycollection1.Count == 0) && (querycollection2.Count == 0))
            {
                collectionid = "CAS0029E";
                macaddress = "XXXXXXXXX";
                smbiosguid = txtuuid.Text.ToString();
                netbiosname = txtname.Text.ToString();
                macaddress = macaddress.Replace("-", ":");
                Dictionary<String, Object> newcomp = new Dictionary<String, Object>();
                newcomp.Add("NetbiosName", netbiosname);
                newcomp.Add("SMBIOSUUID", smbiosguid);
                newcomp.Add("MACAddress", macaddress);
                newcomp.Add("OverwriteExistingRecord", false);
                newcomp.Add("AddToCollection", true);
                newcomp.Add("CollectionId",collectionid);

                    ManagementClass conn = new ManagementClass(scope.Path.Path, "SMS_Site", null);
                    ManagementBaseObject inparams = conn.GetMethodParameters("ImportMachineEntry");
                    inparams["NetbiosName"] = netbiosname;
                    inparams["SMBIOSGUID"] = smbiosguid;
                    inparams["MACAddress"] = macaddress;
                    inparams["OverwriteExistingRecord"] = false;
                    inparams["AddToCollection"] = true;
                    inparams["CollectionId"] = collectionid;
                    //string outparamss;
                    InvokeMethodOptions imo = new InvokeMethodOptions();
                    imo.Timeout = System.TimeSpan.MaxValue;
                try
                {
                    ManagementBaseObject outparams = conn.InvokeMethod("ImportMachineEntry", inparams, imo);
                    lblmsg.Text = "Successfully added machine " + netbiosname + " with resourceid " + outparams["Resourceid"];
                    //msgboxmsg = "Successfully added machine " + netbiosname + " with resourceid " + outconn["Resourceid"];
                    //System.Windows.Forms.MessageBox.Show(msgboxmsg);
                }
                catch (SmsException eer)
                {
                    msgboxmsg = "Failed with error " + eer.Message;
                    System.Windows.Forms.MessageBox.Show(msgboxmsg);
                }

    Wednesday, May 9, 2018 4:49 PM

All replies

  • The stack trace reveals a couple of things. One this is a web app and opens up a whole can of worms since permissions come into play. The actual exception is occurring in your btnSave_Click method in default.aspx at line 92. What is that exact line of code doing? Is there an inner exception with more information? Have you verified the permissions for the app pool to actually use WMI?

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, May 9, 2018 5:17 PM
    Moderator