Link to home
Start Free TrialLog in
Avatar of ammotroop
ammotroop

asked on

C# .Net and MOF


Hi experts,

Need more advanced help.  So I am currently in the process of checking out the new BCD WMI instructions and it keeps talking about a BCD.mof file.  I know very little about MOF files and was hoping someone could shed some light on them.  Also, can someone give me an example of what they even look like or how to program them.  I am afraid that it is going to be built in C++ but are hoping I can build in C#.  Basically what I want is to have a dll file that contains all the functions for running the BCD WMI functions for managing Vista and other OS's installed on a computer.  If someone can shed some light on the BCD.mof or any type of MOF file I would greatly appreciate it.

Thanks,
Jason
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Description:

http://windowssdk.msdn.microsoft.com/en-us/library/ms676627.aspx

The Bcd.mof file defines the Boot Configuration Data (BCD) provider. You can access the BCD provider classes in the Root\WMI namespace. For more information about WMI, see Windows Management Instrumentation.

Are you looking for examples of these?

http://windowssdk.msdn.microsoft.com/en-us/library/ms676625.aspx

Bob
Avatar of ammotroop
ammotroop

ASKER

Well, I have the entire methods working in VB .Net except that VB does not recogniz or has trouble converting an integer into an unsigned integer.  So I converted it to C# only to realize that the GetObject method does not work like it does in VB.  So basically, I have seen that you can build .mof files to hold your classes and objects.  I was wondering if this can be done in C#, unless someone can point me in the right direction for replacing the GetObject method in C#.

Thanks,

Jason
Jason,

1) VB.NET can deal with unsigned integers, you just have to know the magic

2) You can still use the GetObject call, if you add a reference in C# to the Microsoft.VisualBasic runtime library and look at Microsoft.VisualBasic.Interaction.GetObject

3) In pure C#, you can use the Activator class to create late-bound instances.

Bob
Thanks for the info.  I might implement that later on or revert back to it but are having fun with C#.  I am starting to like it better than VB.  :)

I am using the ManagementClass in order to connect to WMI and get the info that I need.  My question is how would I return a class out of WMI into a C# class, if this is possible.  The ways that I have tried have not worked.  The return class is in MOF format.  Is there a way to convert it to a C# class.  Thanks for any help.

Also, what is the "magic" for unsigned integers in VB.Net.  I remember reading it is possible marshalling the integers but I haven't seen it actually done.  Thanks again.

Jason
I know that people are pretty busy and don't want to sound like a pain but I am exhausted with trying different things and failing.  If anyone knows of a way please enlighten me.  Here is what my code looks like.

namespace PROnetworksBCD
{

    //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
    public class BcdStore
    {
        public string FilePath;
    }

    public class BcdStoreMethods
    {
        private ManagementBaseObject inParameters;
        private ManagementBaseObject outParameters;
        private InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.MaxValue);

        private ManagementClass WMIClass = new ManagementClass("\\\\.\\ROOT\\wmi:BcdStore");

        public Boolean OpenStore(string File, ref BcdStore Store)
        {
            try
            {
                inParameters = WMIClass.GetMethodParameters("OpenStore");

                inParameters["File"] = File;

                outParameters = WMIClass.InvokeMethod("OpenStore", inParameters, methodOptions);

                Store = outParameters.GetPropertyValue("Store") as BcdStore;

                //Store = outParameters["Store"] as BcdStore;

                MessageBox.Show(Store.FilePath);

                return Convert.ToBoolean(outParameters["ReturnValue"]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
    }
}


Thanks again for any help.

Jason
What exceptions/indications are you getting from this code?

Bob
Bob,

I am getting object reference not set to an instance.  I have tried everything that I know of even going as far as having BcdStore inherit an the object class.  But that did not work either.  Thanks for any help.

Jason
Is that happening on this line?

    Store = outParameters.GetPropertyValue("Store") as BcdStore;

Bob
That is correct.  When I uncomment the Store = outParameters["Store"] I get the same error.  Any thoughts?  Thanks again.

Jason
What is the type for this?

    outParameters.GetPropertyValue("Store")

Bob
For the out parameter "Store" -> BcdStore the GetPropertyValue("Store") I believe is a ManagementBaseObject.  If this helps here is what outParameters.GetText(TextFormat.Mof) returns.

instance of _PARAMETERS
{
  ReturnValue = TRUE;
  Store =

instance of BcdStore
{
  FilePath="D:\whatever";
};
};

Thanks,
Jason
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please disregard.  Bob gave me an idea and it ended up working just like he posted.  Thanks man.  Sorry it took so long.

Jason