Start a Conversation

Unsolved

This post is more than 5 years old

220129

July 21st, 2014 11:00

OMCI in C#

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!

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.  

12 Posts

July 22nd, 2014 09:00

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);

Again Thanks for the help!

July 22nd, 2014 23:00

Hi Eddie,

The strNewOrder format seems to be wrong here.Give a try on this.

Array should not be like 0,2,3 .

Run the below command in admin cmd prompt (OMCI installed machine).
wmic /namespace:\\root\dcim\sysman path dcim_orderedcomponent get partcomponent

this will give a output like below list ( this is the current array which needs to be modified for changing the boot order ) .

\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-3"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-1"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-2"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-4"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-5"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-2:index-0"

you need to modify the boot order array like below or as you wish.
strNewOrder

\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-5"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-4"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-3"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-2"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-1:index-1"
\\computername\root\dcim\sysman:DCIM_BootSourceSetting.InstanceID="DCIM:BootSoureSetting:UEFI:BootListType-2:index-0"


Then finally you need to use the modified array strNewOrder in the Invokemethod class.

To find the exact boot order string ( like USB, DVD rom, HDD etc. ) you need to map the order with the class Dcim_BootSourceSetting

12 Posts

July 24th, 2014 18:00

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 :)

12 Posts

July 30th, 2014 06:00

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!

August 5th, 2014 08:00

Hi Eddie, 

if this same works in other machines, then this could be a Bios bug also. can you please share us Bios version details so that we can check the same . 

12 Posts

August 5th, 2014 08:00

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!

12 Posts

August 5th, 2014 08:00

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!

August 10th, 2014 23:00

Hi Eddie.

             A few questions in this regards

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

12 Posts

August 11th, 2014 16:00

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.

12 Posts

August 24th, 2014 12:00

Quick question on OMCI, but this time on Trusted Platform Module Activation. I am able to run powershell command to enable TPM, but not able to Activate it, tried 3 different laptop models with latest BIOS and latest OMCI. This works Fine and Enables TPM: (gwmi DCIM_BIOSService -namespace root\dcim\sysman).SetBIOSAttributes($null,$null,"Trusted Platform Module","1",$null) This does not work and cant activate TPM: (gwmi DCIM_BIOSService -namespace root\dcim\sysman).SetBIOSAttributes($null,$null,"Trusted Platform Module Activation","2",$null) Exception calling "SetBIOSAttributes" : "Invalid parameter " At line:1 char:70 + (gwmi DCIM_BIOSService -namespace root\dcim\sysman).SetBIOSAttributes <<<

August 31st, 2014 23:00

Hi Eddi,

I assume you have set the BIOS password before you are trying to run the script. It is mandatory to set the BIOS password to set TPM.

12 Posts

September 2nd, 2014 09:00

You are correct, setting up BIOS password does the trick :)

September 10th, 2014 10:00

Hi Eddie,

I assume your problem seems to be resolved. Will be glad if you could post the code for others use.

12 Posts

September 11th, 2014 06:00

Absolutely,  with all the help on this forum I made a solution to set boot order to use only the main HDD and disables all other devices, but this can be worked to any other solution, also turns on TPM and allows copying Bitlocker keys on: 6400, 6510, 755, 5520, 5530, 5400, 5440 models I tested so far...Hope this helps :)

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dell_Boot_TPM
{
    public partial class Form1 : Form
    {       
        public Form1()
        {
            InitializeComponent();
            textBox4.ReadOnly = true;
            textBox5.ReadOnly = true;
            textBox6.ReadOnly = true;           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private bool ValidateName()
        {
            bool bStatus = true;
            if (textBox1.Text == "")
            {
                errorProvider1.SetError(textBox1, "Please Enter Username!");
                bStatus = false;
            }
            else
                errorProvider1.SetError(textBox1, "");
            return bStatus;
        }

        private bool ValidatePassword()
        {
            bool bStatus = true;
            if (textBox2.Text == "")
            {
                errorProvider2.SetError(textBox2, "Please Enter Password!");
                bStatus = false;
            }
            else
                errorProvider2.SetError(textBox2, "");
            return bStatus;
        }

        private bool ValidateSerial()
        {
            bool bStatus = true;
            if (textBox3.Text == "")
            {
                errorProvider3.SetError(textBox3, "Please Enter PC Serial or IP!");
                bStatus = false;
            }
            else
                errorProvider3.SetError(textBox3, "");
            return bStatus;
        }
 

        private void button1_Click(object sender, EventArgs e)
        {
            ValidateName();
            ValidatePassword();
            ValidateSerial();      
            string username = textBox1.Text;
            string password = textBox2.Text;
            string serial = textBox3.Text;      
            changeBoot(serial, username, password);
        }

        private void changeBoot(string host, string username, string password)
        {
            try
            {
                string serial = textBox3.Text;

                ConnectionOptions coWMI = new ConnectionOptions();
                if (!string.IsNullOrEmpty(username))
                {
                    coWMI.Username = username;
                    coWMI.Password = password;
                    coWMI.Authentication = AuthenticationLevel.PacketPrivacy;
                    coWMI.Impersonation = ImpersonationLevel.Impersonate;
                    coWMI.EnablePrivileges = true;
                }                           

                ManagementScope DellmsRP = new ManagementScope("\\\\" + serial + "\\root\\dcim\\sysman", coWMI);
                DellmsRP.Connect();
                ObjectQuery BootSource = new ObjectQuery("SELECT * FROM DCIM_BootSourceSetting");
                ManagementObjectSearcher BootSourceOrder = new ManagementObjectSearcher(DellmsRP, BootSource);
                ArrayList element = new ArrayList();
                ArrayList instance = new ArrayList();
                foreach (ManagementObject queryObjBoot in BootSourceOrder.Get())
                {
                    element.Add(queryObjBoot["ElementName"].ToString());
                    instance.Add(queryObjBoot["InstanceID"].ToString());
                }

                string index;
                ArrayList device = new ArrayList();
                //For UEFI Systems
                //index = "UEFI: Hard Drive";
                //device.Add(index);                

                //6400 6510
                if (radioButton2.Checked)
                {
                    index = "Internal HDD (IRRT)";
                    device.Add(index);
                }
                //755
                else if (radioButton1.Checked)
                {
                    index = "Hard drive";
                    device.Add(index);
                }
                //5520 5530 5400 5440
                else if (radioButton3.Checked)
                {
                    index = "Internal HDD";
                    device.Add(index);
                }
                //390 no TPM
                else if (radioButton4.Checked)
                {
                    textBox5.Text = "System does not have TPM Module";
                    string subString = "SATA:";
                    foreach (string item in element)
                    {
                        if (item.Contains(subString))
                        {
                            device.Add(item);
                        }
                    }                  
                }
                //780
                else if (radioButton5.Checked)
                {                 
                    index = "Hard drive";
                    device.Add(index);
                }

                int indexItem = element.IndexOf(device[0]);
                element.Add(indexItem);
                string modorder = instance[indexItem].ToString();

                ObjectQuery BootConfig = new ObjectQuery("SELECT * FROM DCIM_BootConfigSetting");
                ManagementObjectSearcher BootConfigOrder = new ManagementObjectSearcher(DellmsRP, BootConfig);
                ManagementObjectCollection oc = BootConfigOrder.Get();
                ManagementObjectCollection.ManagementObjectEnumerator oe = oc.GetEnumerator();

                if (oc.Count != 0)
                {
                    while (oe.MoveNext())
                    {
                        ArrayList properties = new ArrayList();
                        ArrayList indexNumber = new ArrayList();
                        foreach (PropertyData prop in oe.Current.Properties)
                        {
                            properties.Add(prop.Value);
                        }
                       
                        if (properties[5].ToString() == "DCIM:BootConfigSetting:Next")
                        {
                            object[] boot = { "//" + serial + "/root/dcim/sysman:DCIM_BootSourceSetting.InstanceID=\"" + modorder + "\"" };
                            ManagementObject classInstance = new ManagementObject("\\\\" + serial + "\\root\\dcim\\sysman", "DCIM_BootConfigSetting.InstanceID='" + properties[5] + "'", null);
                            ManagementBaseObject inParams = classInstance.GetMethodParameters("ChangeBootOrder");
                            inParams["AuthorizationToken"] = "";
                            inParams["source"] = boot;
                            ManagementBaseObject outParams = classInstance.InvokeMethod("ChangeBootOrder", inParams, null);
                        }
                        else
                        {
                            object[] boot = { "//" + serial + "/root/dcim/sysman:DCIM_BootSourceSetting.InstanceID=\"" + modorder + "\"" };
                            ManagementObject classInstance = new ManagementObject("\\\\" + serial + "\\root\\dcim\\sysman", "DCIM_BootConfigSetting.InstanceID='" + properties[5] + "'", null);
                            ManagementBaseObject inParams = classInstance.GetMethodParameters("ChangeBootOrder");
                            inParams["AuthorizationToken"] =  "";
                            inParams["source"] = boot;
                            ManagementBaseObject outParams = classInstance.InvokeMethod("ChangeBootOrder", inParams, null);
                        }
                        textBox4.Text = "PC: " + serial + " Boot Order Changed Successfully, Changes Will Take Effect After Reboot!";

                        //Enable TPM
                        ObjectQuery BiosTPM = new ObjectQuery("SELECT * FROM DCIM_BIOSEnumeration");
                        ManagementObjectSearcher EnumTPM = new ManagementObjectSearcher(DellmsRP, BiosTPM);

                        string strKeyValue = "Root/MainSystemChassis/BIOSSetupParent/BiosSetupTPM";
                        ArrayList instances = new ArrayList();
                        ArrayList values = new ArrayList();
                        ArrayList names = new ArrayList();

                        foreach (ManagementObject queryObjTPM in EnumTPM.Get())
                        {
                            instances.Add(queryObjTPM["InstanceID"].ToString());
                            values.Add(queryObjTPM["CurrentValue"]);
                            names.Add(queryObjTPM["AttributeName"].ToString());
                            if (queryObjTPM["InstanceID"].ToString().Equals(strKeyValue))
                            {
                                break;
                            }
                        }                      
                        int indexTPM = instances.IndexOf(strKeyValue);
                        string tpmindex = instances[indexTPM].ToString();
                        foreach (var value in values.OfType ().ElementAt(indexTPM))
                        {
                            if (value == "2")
                            {
                                var tpm = @"(gwmi DCIM_BIOSService -namespace root\dcim\sysman -cn " + serial + ").SetBIOSAttributes($null,$null,'Trusted Platform Module','1', $null)";
                                var shell = PowerShell.Create();
                                shell.Commands.AddScript(tpm.ToString());
                                var results = shell.Invoke();
                                textBox5.Text = "Serial: " + serial + " TPM Is Now Enabled!";
                            }
                            else
                            {
                                textBox5.Text = "PC: " + serial + " TPM Already Enabled!";
                            }
                        }
                    }
                }
                else
                {
                    textBox4.Text = "PC: " + serial + " does not have OMCI Installed!";
                }
            }
            catch (ManagementException err)
            {
                string serial = textBox4.Text;
                textBox4.Text = "PC: " + serial + " Error Accessing System " + err.Message + " or does not have OMCI Installed!";
            }
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        protected bool Bitlocker()
        {
            try
            {
                string username = textBox1.Text;
                string password = textBox2.Text;
                string serial = textBox3.Text;
                ManagementPath path = new ManagementPath();
                path.Server = serial;
                path.NamespacePath = "\\ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption";
                path.ClassName = "Win32_EncryptableVolume";
                ConnectionOptions options = new ConnectionOptions();
                options.Username = username;
                options.Password = password;
                options.Authentication = AuthenticationLevel.PacketPrivacy;
                options.Impersonation = ImpersonationLevel.Impersonate;
                options.EnablePrivileges = true;
                ManagementScope scope = new ManagementScope(path, options);
                ObjectGetOptions getOptions = new ObjectGetOptions();
                ManagementClass management = new ManagementClass(scope, path, getOptions);
                management.Get();
                foreach (var vol in management.GetInstances())
                    if ((uint)vol["ProtectionStatus"] == 1)
                    {
                        return true;
                    }
                return false;
            }
            catch (ManagementException err)
            {
                string serial = textBox3.Text;
                textBox6.Text = "PC: " + serial + " Error Accessing System " + err.Message;
            }
            return false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ValidateName();
            ValidatePassword();
            ValidateSerial();          
            if (Bitlocker())
            {
                try
                {
                    string username = textBox1.Text;
                    string password = textBox2.Text;
                    string serial = textBox3.Text;
                    string strManageBDEPath = @"C:\Windows\System32\";
                    ConnectionOptions connOptions = new ConnectionOptions();
                    connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
                    connOptions.Impersonation = ImpersonationLevel.Impersonate;
                    connOptions.Username = username;
                    connOptions.Password = password;
                    ManagementScope mgtScope = new ManagementScope("\\\\" + serial + "\\ROOT\\CIMV2", connOptions);
                    mgtScope.Connect();
                    ObjectGetOptions objectGetOptions = new ObjectGetOptions();
                    ManagementPath mgtPath = new ManagementPath("Win32_Process");
                    ManagementClass processClass = new ManagementClass(mgtScope, mgtPath, objectGetOptions);
                    ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
                    inParams["CommandLine"] = "cmd.exe /k" + strManageBDEPath + "manage-bde" + " -cn " + serial + " -protectors -get c: >" + @"C:\" + serial + ".txt";
                    ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
                    string fileToCopy = @"\\" + serial + "\\C$\\" + serial + ".txt";
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.InitialDirectory = @"C:\";
                    sfd.FileName = fileToCopy;
                    sfd.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
                    sfd.FilterIndex = 1;
                    sfd.RestoreDirectory = true;
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        System.IO.File.Copy(fileToCopy, sfd.FileName, true);
                    }
                    textBox6.Text = "Bitlocker Key also Copied to the Root of C: on " + serial;
                }
                catch (ManagementException err)
                {
                    string serial = textBox3.Text;
                    textBox6.Text = "PC: " + serial + " Could Not Save Bitlocker File, Try Again!" + " Error Accessing System " + err.Message;
                }
            }
            else
            {
                string serial = textBox3.Text;
                textBox6.Text = "PC: " + serial + " Bitlocker Paused or System Not Bitlocked Yet!";
            }
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {

        }
     

        private void button3_Click(object sender, EventArgs e)
        {
            ValidateName();
            ValidatePassword();
            ValidateSerial();          
            try
            {
                string username = textBox1.Text;
                string password = textBox2.Text;
                string serial = textBox3.Text;
                ConnectionOptions coWMI = new ConnectionOptions();
                coWMI.Username = username;
                coWMI.Password = password;
                coWMI.Authentication = AuthenticationLevel.PacketPrivacy;
                coWMI.Impersonation = ImpersonationLevel.Impersonate;
                coWMI.EnablePrivileges = true;
                //Creates Remote Process on Selected System to Restart it in 30 seconds
                ManagementScope msRP = new ManagementScope("\\\\" + serial + "\\root\\cimv2", coWMI);
                msRP.Connect();
                ObjectGetOptions ogoRP = new ObjectGetOptions();
                ManagementPath mpRP = new ManagementPath("Win32_Process");
                ManagementClass mcRP = new ManagementClass(msRP, mpRP, ogoRP);
                ManagementBaseObject inParams = mcRP.GetMethodParameters("Create");
                inParams["CommandLine"] = @"shutdown /r /t 30";
                ManagementBaseObject outParams = mcRP.InvokeMethod("Create", inParams, null);
                textBox4.Text = "PC: " + serial + " will Restart in 30 seconds";
            }
            catch
            {
                string serial = textBox3.Text;
                textBox4.Text = "PC: " + serial + " Error Accessing System.";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }       

    }
}

No Events found!

Top