I am trying to incorporate OMCI into my existing C#.net application. To be exact I am trying to change boot order to a remote PC.
So far I can enumerate the current boot order of a remote PC like:
ManagementPath path = new ManagementPath("\\\\" + computername+ "\\root\\dcim\\sysman"); ManagementScope scope = new ManagementScope(path, coWMI); SelectQuery BootConfigSetting = new SelectQuery("SELECT * FROM DCIM_BootConfigSetting"); ManagementObjectSearcher bootconfig = new ManagementObjectSearcher(scope, BootConfigSetting); SelectQuery ElementSettingData = new SelectQuery("SELECT * FROM DCIM_ElementSettingData"); ManagementObjectSearcher element = new ManagementObjectSearcher(scope, ElementSettingData); SelectQuery BootSourceSetting = new SelectQuery("SELECT * FROM DCIM_BootSourceSetting"); ManagementObjectSearcher bootsource = new ManagementObjectSearcher(scope, BootSourceSetting); SelectQuery OrderedComponent = new SelectQuery("SELECT * FROM DCIM_OrderedComponent"); ManagementObjectSearcher ordered = new ManagementObjectSearcher(scope, OrderedComponent);
foreach (ManagementObject oldorder in ordered.Get()) {
Response.Write("");
}
I need help translating either powershell or vbscript "ChangeBootOrder" Method into C# without using PowerShell Pipelines if possible.
Any help or direction will be greatly appreciated!
You need to use the InvokeMethod Class ( C# ) for setting "ChangeBootOrder" on DCIM_BootConfigSetting Class of Dell OMCI to set the boot order values. you need to give your modified Array in the source parameter of this method. this array is nothing but the list of "PartComponent" property in DCIM_OrderedComponent class in Dell OMCI.
Below link is sample of Invokemethod for WMI namespace . you can use the same way by using the Dell OMCI namespace.
Thanks for the quick response, I really appreciate it. I am a bit confused how to set the new order array and iIam getting an Error "Not found" when I try to pass the array....I am very new to C# so excuse my inexperience. I re-factored a WMI part i already have working to start and shutdown remote pcs and i am trying to adapt it to change the boot order on the Dells, please let me know what I am doing wrong:
string serial = "123456"; ConnectionOptions coWMI = new ConnectionOptions(); string Username = WebConfigurationManager.AppSettings["Username"].ToString(); string Password = WebConfigurationManager.AppSettings["Password"].ToString(); string Authority = WebConfigurationManager.AppSettings["Authority"].ToString(); coWMI.Username = Username; coWMI.Password = Password; coWMI.Authority = Authority; ManagementScope msRP = new ManagementScope(@"\\" + serial + "\\root\\dcim\\sysman", coWMI); msRP.Connect(); ObjectGetOptions ogoRP = new ObjectGetOptions(); ManagementPath mpRP = new ManagementPath("Dcim_BootConfigSetting"); ManagementClass mcRP = new ManagementClass(msRP, mpRP, ogoRP); ManagementBaseObject inParams = mcRP.GetMethodParameters("ChangeBootOrder"); object[] strNewOrder = { "0", "2", "3" }; // not sure how to pass the array of modified boot order here! inParams["PartComponent"] = strNewOrder; //Not Found Error! not even sure if PartComponent is the ///correct property to set here. inParams["Password"] = Password; ManagementBaseObject outParams = mcRP.InvokeMethod("ChangeBootOrder", inParams, null);
I am still struggling a bit trying to get this to work right, when I run the command in my test pc which is not UEFI capable: wmic /namespace:\\root\dcim\sysman path dcim_orderedcomponent get partcomponent it returns back in this format: \\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSett ing:IPL:1" When I pass the array as noted in the example I still get the exception "Not Found" while invoking. using System; using System.Collections.Generic; using System.Linq; using System.Management; using System.Web; using System.Web.Configuration; using System.Web.UI; using System.Web.UI.WebControls; namespace Dell_Boot { public partial class WebForm4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { NewBootOrder(); } void NewBootOrder() { string pcname = "123456"; ConnectionOptions coWMI = new ConnectionOptions(); string Username = WebConfigurationManager.AppSettings["Username"].ToString(); string Password = WebConfigurationManager.AppSettings["Password"].ToString(); string Authority = WebConfigurationManager.AppSettings["Authority"].ToString(); coWMI.Username = Username; coWMI.Password = Password; coWMI.Authority = Authority; ManagementScope msRP = new ManagementScope("\\\\" + pcname + "\\root\\dcim\\sysman", coWMI); msRP.Connect(); // Get the object on which the // method will be invoked ManagementClass processClass = new ManagementClass("DCIM_BootConfigSetting"); object[] strNewOrder={ @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-0", //also tried in this format, no go either: //@"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:IPL:1" @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-1", @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-2", @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-3", @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-4", @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-5", @"\\"+pcname+@"\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID=DCIM:BootSoureSetting:BootListType-1:index-6"}; // Create an array containing all // arguments for the method object[] methodArgs = { strNewOrder, Password, null }; //Execute the method object result = processClass.InvokeMethod("ChangeBootOrder", methodArgs);//keep getting exception not found! } } } Again, any input will be very appreciated :)
Ok I figured out the exception "not Found" issue, though I am getting invalid parameters when I invoke the "ChangeBootOrder" Method. My array is identical (except the order I rearranged) to the output from: wmic /namespace:\\root\dcim\sysman path dcim_orderedcomponent get partcomponent as noted. I am using a UEFI laptop now and the output is now exactly as: \\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-3" Here is my code: void NewBootOrder() { string pcname = "123456"; ConnectionOptions coWMI = new ConnectionOptions(); string Username = WebConfigurationManager.AppSettings["Username"].ToString(); string Password = WebConfigurationManager.AppSettings["Password"].ToString(); string Authority = WebConfigurationManager.AppSettings["Authority"].ToString(); coWMI.Username = Username; coWMI.Password = Password; coWMI.Authority = Authority; ManagementScope msRP = new ManagementScope("\\\\" + pcname + "\\root\\dcim\\sysman", coWMI); msRP.Connect(); ObjectGetOptions ogoRP = new ObjectGetOptions(); ManagementPath mpRP = new ManagementPath("DCIM_BootConfigSetting"); ManagementClass mcRP = new ManagementClass(msRP, mpRP, ogoRP); SelectQuery BootSourceSetting = new SelectQuery("SELECT * FROM DCIM_BootSourceSetting"); ManagementObjectSearcher bootsource = new ManagementObjectSearcher(msRP, BootSourceSetting); ManagementObjectCollection orderColl = bootsource.Get(); ManagementObject[] orderArray = new ManagementObject[orderColl.Count]; orderColl.CopyTo(orderArray, 0); //New Boot Order Array object[] strNewOrder = new object[7]; strNewOrder[0] = orderArray:emotion-14:; strNewOrder[1] = orderArray[5]; strNewOrder[2] = orderArray[4]; strNewOrder[3] = orderArray[3]; strNewOrder[4] = orderArray[2]; strNewOrder[5] = orderArray[1]; strNewOrder:emotion-14: = orderArray[0]; object[] NewBoot = { strNewOrder, Password, null }; // Error Invalid Parameters object ChangeBoot = mcRP.InvokeMethod("ChangeBootOrder", NewBoot); } Again any direction will be appreciated greatly!
I've been chasing my tail for a few weeks now and I think these new E5440 are somewhat different and cant get any the scripts to change the boot order. Running: (gwmi -namespace root\dcim\sysman -class dcim_bootconfigsetting).getmethodparameters("ChangeBootOrder") Gets me: Method invocation failed because [System.Object[]] doesn't contain a method named 'getmethodparameters'. At line:1 char:85 + (gwmi -namespace root\dcim\sysman -class dcim_bootconfigsetting).getmethodparameters("ChangeBootOrder") + CategoryInfo : InvalidOperation: (getmethodparameters:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound. Running cscript.exe //nologo SampleSetBootOrder.vbs localhost Gets me: C:\Tools\Dell Scripts\SampleSetBootOrder.vbs(117, 2) SWbemObjectEx: Invalid parameter. Same problem when running my C# application. I have no issues with older BIOS laptops. We are installing W7 64 bit with Secure Boot OFF Legacy Mode if that would that make a difference? or is related to the Laptop Model? Any help will be greatly appreciated!
These are all using BIOS A07 System Manufacturer Dell Inc. System Model Latitude E5440 System Type x64-based PC Processor Intel(R) Core(TM) i3-4010U CPU @ 1.70GHz, 1701 Mhz, 2 Core(s), 4 Logical Processor(s) BIOS Version/Date Dell Inc. A07, 6/26/2014 SMBIOS Version 2.7 Boot Device \Device\HarddiskVolume2 I did tried the new E5440A07 from your site with the same results, we have over 30 of these laptops and its creating issues not been able to set boot order via scripts, thanks again for all the help!
1. Do you see the behavior consistent across all your systems.
2. Can you check if the DSM Data manager service is running on the system or not?
3. I assume you are using the latest version of OMCI available (v8.2.1) and all its dependencies met.
Since we are not able to reproduce the stated behavior here. We would need more help from you in understand the environment setup you have to help us resolve this at the earliest. Kindly also share any other information incase you feel its needed
1. Yes, the behavior is identical on 5 laptops I tried out of 25. 2. Correct, DSM services are running. 3. Correct OMCI version is 8.2.1.70 I am unable to run sample ps1 nor vbs scripts locally, always returning the same error: InvalidOperation: (getmethodparameters:String) [], RuntimeException as noted before. do not see the error on older BIOS laptops like XT2, ,E5400, E6400 etc.. same scripts... Oddly, since I really did not want to run scripts locally anyways, I managed to get C# to remotely changed the boot order as I originally wanted on all models. I will post my completed ASP.net C# once finalized in case someone else needs it.
karthikchandran89
1 Rookie
•
49 Posts
5679
0
Posted July 22nd, 2014 05:00
Hi Eddie,
You need to use the InvokeMethod Class ( C# ) for setting "ChangeBootOrder" on DCIM_BootConfigSetting Class of Dell OMCI to set the boot order values. you need to give your modified Array in the source parameter of this method.
this array is nothing but the list of "PartComponent" property in DCIM_OrderedComponent class in Dell OMCI.
Below link is sample of Invokemethod for WMI namespace . you can use the same way by using the Dell OMCI namespace.
http://msdn.microsoft.com/en-us/library/f9ck6sf2(v=vs.110).aspx
// Get the object on which the
// method will be invoked
ManagementClass processClass = new ManagementClass("Dcim_BootConfigSetting");
// Create an array containing all
// arguments for the method
object[] methodArgs = {"your array to set ", "password if set" , null };
//Execute the method
object result = processClass.InvokeMethod( "ChangeBootOrder", methodArgs);
Please share the observations.