Jump to content

Use of WMI in LabVIEW


Recommended Posts

Hi people,

I want to read the ID of the hard drive of a computer and I've read that it is posible using WMI of Microsoft but I don't how to use so, is there anybody who knows?

Bye

Try this post:

Kernel32.dll call to get volume info

Cheers,

PS: A little use of the Search feature makes it easy to find stuff like this.

Link to post
Share on other sites

Hi Michael,

Firstly, thanks for answering so quickly.

I've been reading some messages in the forum of National Instruments and I've got the VI that I atach you.

The VI uses .NET platform to comunicate with WMI (Windows Management Instrumentation) that is an API to Windows OS. With this I can do what I wanted. It's necessary to be installed .NET Framework in the computer but it can be downloaded from www.microsoft.com and it's redistributable.

cheers

Download File:post-4923-1149835114.vi

Link to post
Share on other sites

JdP, you're welcome. Yes, the .NET - WMI method works. Thanks for posting the VI you have, however, if you got this off of NI's site you may not be able to post it hear, depending on the license. Please check the applicable license or Terms Of Use agreement for where you got it from. It is permissible to post a link to the topic at NI's forums and that is the prefered method. If you did this VI yourself, kudo's.

The only problem with the .NET method is the needed installation of the .NET framework, whereas the kernel32 call is simple and works as is. YMMV

Link to post
Share on other sites

Hello Michael,

I think there isn't any problem with the VI because I got it from a person who post it in discussion forum in the NI's website so, I suppose that the 'intellectual property' belongs to the person who post it in the web and no to NI. And when you put something in a forum like this or like NI's forum is to other people helps you and uses code you post.

I know that it's neccesary to have installed in the computer the .NET framework. This is quite normal nowdays because the new applications are programmed with .NET within Visual Studio .NET of Microsoft. I've got one program from Microsoft that can be interested. The name is 'Microsoft Component Installer Software Development Kit for Windows (x86) Version 2.0'. It can be downloaded from the following link:

http://www.microsoft.com/downloads/details...&DisplayLang=en

With this program you can do an Installer CD to install the necessary MS components for you application. There is help file. I've just used to install the .NET framework and after that I excute the installer of my LabVIEW program.

Cheers,

Link to post
Share on other sites
Hello Michael,

I think there isn't any problem with the VI because I got it from a person who post it in discussion forum in the NI's website so, I suppose that the 'intellectual property' belongs to the person who post it in the web and no to NI. And when you put something in a forum like this or like NI's forum is to other people helps you and uses code you post.

I know that it's neccesary to have installed in the computer the .NET framework. This is quite normal nowdays because the new applications are programmed with .NET within Visual Studio .NET of Microsoft. I've got one program from Microsoft that can be interested. The name is 'Microsoft Component Installer Software Development Kit for Windows (x86) Version 2.0'. It can be downloaded from the following link:

http://www.microsoft.com/downloads/details...&DisplayLang=en

With this program you can do an Installer CD to install the necessary MS components for you application. There is help file. I've just used to install the .NET framework and after that I excute the installer of my LabVIEW program.

Cheers,

I know this might be a moot point with LabVIEW 8 only supporting 2000 and XP anyhow, but there are many people still running on older LabVIEW versions and Windows OSes. And for them .Net is not just an inconvinience but simply an impossibility. So why use a high tech laser cutter for something where a simple pocket knife will do more than well enough?

Rolf Kalbermatter

Link to post
Share on other sites
I know this might be a moot point with LabVIEW 8 only supporting 2000 and XP anyhow, but there are many people still running on older LabVIEW versions and Windows OSes. And for them .Net is not just an inconvinience but simply an impossibility. So why use a high tech laser cutter for something where a simple pocket knife will do more than well enough?

Rolf Kalbermatter

I suppose that you're right. I only wanted to start to use WMI because it's very useful to communicate with MS Windows OS. With WMI you can do a lot of things with the same interface.

Link to post
Share on other sites
I suppose that you're right. I only wanted to start to use WMI because it's very useful to communicate with MS Windows OS. With WMI you can do a lot of things with the same interface.

Rolf is right about the hi-low tech trade off. Liberal use of Occum's Razor will keep your code neat and portable over the years. However, it is also good to learn new and more powerful interfaces/APIs, so perhaps your use of WMI on this simple case will give you some experience that you can use later on more complicated problems that actually require something with the power of WMI.

Elegant, well written code almost always uses the simplest means to get the job done.

Link to post
Share on other sites
  • 3 weeks later...
Hi people,

I want to read the ID of the hard drive of a computer and I've read that it is posible using WMI of Microsoft but I don't how to use so, is there anybody who knows?

Bye

Hi

In alternative you can use the utility attached, that report any data from the drives of the PC... You can call the utility via the System Exec VI... :thumbup:

Osvaldo

Download File:post-457-1151488070.zip

Link to post
Share on other sites
Hi

In alternative you can use the utility attached, that report any data from the drives of the PC... You can call the utility via the System Exec VI... :thumbup:

Osvaldo

Hello Osvaldo,

Thanks for posting this executable file. It is a very easy and simple solution to get the Id of the hard disk. The only problem I've seen is that the output of the command is not direct so I must use String functions to get the HardDisk_Id that is the only what I want.

Thanks again.

Link to post
Share on other sites
  • 2 years later...

QUOTE (JdP @ Jun 28 2006, 05:07 AM)

Hello Osvaldo,

Thanks for posting this executable file. It is a very easy and simple solution to get the Id of the hard disk. The only problem I've seen is that the output of the command is not direct so I must use String functions to get the HardDisk_Id that is the only what I want.

Thanks again.

Hello there,

I've read this post with much interest, however from the comments on the NI Forums and here at LAVA have never addressed how to access a byte array returned from the .NET ManagementBaseObject. All postings and examples (which I'm most thankful for!) have always referred to single string parameter output, from the System.Object (ToString) LabVIEW Invoke node. My problem is I'm not a .NET programmer and the literal translation of the .VB .NET, .VBS or C# is not as simple as one would hope. See attached screen shot example from WMI Code Creator.

Imports System

Imports System.Management

Imports System.Windows.Forms

Namespace WMISample

Public Class MyWMIQuery

Public Overloads Shared Function Main() As Integer

Try

Dim searcher As New ManagementObjectSearcher( _

"root\WMI", _

"SELECT * FROM MSStorageDriver_ATAPISmartData")

For Each queryObj As ManagementObject in searcher.Get()

Console.WriteLine("-----------------------------------")

Console.WriteLine("MSStorageDriver_ATAPISmartData instance")

Console.WriteLine("-----------------------------------")

If queryObj("VendorSpecific") Is Nothing Then

Console.WriteLine("VendorSpecific: {0}", queryObj("VendorSpecific"))

Else

Dim arrVendorSpecific As Byte()

arrVendorSpecific = queryObj("VendorSpecific")

For Each arrValue As Byte In arrVendorSpecific

Console.WriteLine("VendorSpecific: {0}", arrValue)

Next

End If

Next

Catch err As ManagementException

MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)

End Try

End Function

End Class

End Namespace

The specifics is translating the two lines, Dim arrVendorSpecific As Byte(), arrVendorSpecific = queryObj("VendorSpecific") into something meaningful that LabVIEW can understand. Ultimately, we should receive a byte array and be able to select the elements as appropriate from this.

Can someone more savvy with .NET and LabVIEW integration help me sleep better at night?

Regards,

Chroma

Link to post
Share on other sites
  • 3 weeks later...

QUOTE (rayodyne @ Apr 23 2009, 12:38 PM)

Hello there,

I've read this post with much interest, however from the comments on the NI Forums and here at LAVA have never addressed how to access a byte array returned from the .NET ManagementBaseObject. All postings and examples (which I'm most thankful for!) have always referred to single string parameter output, from the System.Object (ToString) LabVIEW Invoke node. My problem is I'm not a .NET programmer and the literal translation of the .VB .NET, .VBS or C# is not as simple as one would hope. See attached screen shot example from WMI Code Creator.

Imports System

Imports System.Management

Imports System.Windows.Forms

Namespace WMISample

Public Class MyWMIQuery

Public Overloads Shared Function Main() As Integer

Try

Dim searcher As New ManagementObjectSearcher( _

"root\WMI", _

"SELECT * FROM MSStorageDriver_ATAPISmartData")

For Each queryObj As ManagementObject in searcher.Get()

Console.WriteLine("-----------------------------------")

Console.WriteLine("MSStorageDriver_ATAPISmartData instance")

Console.WriteLine("-----------------------------------")

If queryObj("VendorSpecific") Is Nothing Then

Console.WriteLine("VendorSpecific: {0}", queryObj("VendorSpecific"))

Else

Dim arrVendorSpecific As Byte()

arrVendorSpecific = queryObj("VendorSpecific")

For Each arrValue As Byte In arrVendorSpecific

Console.WriteLine("VendorSpecific: {0}", arrValue)

Next

End If

Next

Catch err As ManagementException

MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)

End Try

End Function

End Class

End Namespace

The specifics is translating the two lines, Dim arrVendorSpecific As Byte(), arrVendorSpecific = queryObj("VendorSpecific") into something meaningful that LabVIEW can understand. Ultimately, we should receive a byte array and be able to select the elements as appropriate from this.

Can someone more savvy with .NET and LabVIEW integration help me sleep better at night?

Regards,

Chroma

No takers?

-Chroma

Link to post
Share on other sites
  • 5 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.