Solved

C# .Net and MOF

Posted on 2006-07-02
14
1,193 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now