Solved

C# .Net and MOF

Posted on 2006-07-02
14
1,207 Views
Last Modified: 2012-06-27

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
0
Comment
Question by:ammotroop
  • 7
  • 6
14 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17026099
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
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17026116
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17030501
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
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:ammotroop
ID: 17034681
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
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17036191
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17043569
What exceptions/indications are you getting from this code?

Bob
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17046596
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17046779
Is that happening on this line?

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

Bob
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17046909
That is correct.  When I uncomment the Store = outParameters["Store"] I get the same error.  Any thoughts?  Thanks again.

Jason
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17046976
What is the type for this?

    outParameters.GetPropertyValue("Store")

Bob
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17047377
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
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17050132
Try this:

   ManagementBaseObject store = (ManagementBaseObject) outParameters.GetPropertyValue("Store");
   string filePath = store["FilePath"];

Bob
0
 
LVL 1

Author Comment

by:ammotroop
ID: 17096344
Please disregard.  Bob gave me an idea and it ended up working just like he posted.  Thanks man.  Sorry it took so long.

Jason
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question