Solved

C# .Net and MOF

Posted on 2006-07-02
14
1,219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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