Solved

C# .Net and MOF

Posted on 2006-07-02
14
1,197 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

14 Experts available now in Live!

Get 1:1 Help Now