Getting Hard Disk Information with WMI and Visual Studio 2. Introduction. Hello again! Today I will talk about how to retrieve hard disk information via WMI. Sometimes it is necessary to know how much free space is available on your disk, what type of drive it is, and/or what file system is being used. Not quite so often, we might need to know what the hard disk's serial number is; especially when we want to let users buy licenses for our programs. I will cover all of these with VB and C#. Let's get the party started! WMIWMI (Windows Management Instrumentation), as quoted from MSDN, is the infrastructure for management data and operations on Windows- based operating systems. OK, in layman's terms this means that via the use of WMI, we can retrieve data that is at the heart of our hardware and / or services. We'll cover the above list of topics today, especially the hard disk serial number, which is not as easy to come by usually. How It Works. There are two ways to make use of WMI in our programs. We could write queries ( similar to SQL / LINQ queries ), known as WQL, to obtain this info, or we could make use of the System. Management and System. Management. Instrumentation namespaces, which have these queries built in. This is what we'll use today. Design. Open Visual Studio 2. VB Windows Forms Project or a C# Windows Forms Project. Give it any name of your choice and add five buttons. Monitor Serial Number using WMI. Archived Forums V > Visual Basic Language. I know I can get the Monitor Serial Number from the WMIMonitorID Class in the Monitor Display Classes. I just don't know the Syntax. Exploring Windows Management Instrumentation in C#. HDD Serial Number; HDD Sizes; HDD Free Space. Using WMI Class in C#: Search: Advanced Forum Search. Forums; Programming; Web Development; Computers; Tutorials; Snippets; Dev Blogs; Jobs; Lounge. HDD Serial Number(s) HDD Sizes; HDD Free Space; CPU Serial Number(s) CPU. Access WMI via C# and retrieve motherboard information; Author: Mohammad Elsheimy; Updated:; Section: C#; Chapter: Languages; Updated. Get the system's board serial numbers and CPU IDs in C#. WMI and tagged board serial number, C#, C# programming. 3 Responses to Get the system’s board serial numbers and CPU IDs in C#. Most flash-based USB disk devices have a unique serial number assigned by the manufacturer. Your design screen should resemble Figure 1: Figure 1 - Our Design. Add the System. Management Reference to your project, by clicking Project, References, System. Management. Namespaces. Add the following namespaces to your code: VB. NET : Imports System. Management. imports System. Management. Instrumentation C# : using System. Management. using System. Management. Instrumentation; Getting the Serial Number. Add the next code segment: VB. NET : Public Function Get. HDSerial. No(By. Val str. Drive As String) As String 'Get HD Serial Number. Ensure Valid Drive Letter Entered, Else, Default To C. If str. Drive = . We then make use of the Win. At the end we reference the Volume. Serial. Number property, which will give us the disk's serial number. Lastly, we called this sub from our Button. Figure 2 - Hard Disk Serial Number. Get Hard Disk Size. Add the next code. VB. NET : Public Function Get. HDSize(By. Val str. Drive As String) As Double 'Get Size of Specified Disk. Ensure Valid Drive Letter Entered, Else, Default To C. If str. Drive = . Just a note, all the coming Functions will operate the same way, so I won't go into too many details again about the methodology used in these functions. The resulting number will not be rounded off. It will also not display KB, MB, GB, or even TB. We have to incorporate that logic ourselves. Luckily, that is quite easy! All we need to do is to divide the result x amount of times with 1. Byte size ). I divided it three times, and it gave me the correct result in Giga. Bytes. Many people do not know the levels of these sizes, that is why I included it in here. Just to be interesting : )Figure 3 - Hard Disk Size. Getting Free space. Add the next code. Obtain System Information using WMI Calls. By Scott Lysle on Apr 06. C#, and VB.NET code that uses WMI to complete a management task such as querying for. Hello, I generated this code with WMI Code Creator and want to convert it for use on a single.aspx page: using System; using System.Management; using System.Windows.Forms; namespace WMISample Learn how to retrieve Motherboard serial number and other related information via Windows Management Instrumentation (WMI) in.NET. VB. NET : Public Function Get. HDFree. Space(By. Val str. Drive As String) As Double. Ensure Valid Drive Letter Entered, Else, Default To C. If str. Drive = . The result will be numeric, so we have to convert that numeric value into something understandable. My hard disk returned 3 - which supports reading and writing. If we were using a CD for example, then it would have been readable only. Figure 5 - Hard Disk Type. Getting the File System. VB. NET : Public Function Get. HDFile. System(By. Val str. Drive As String) As String. Ensure Valid Drive Letter Entered, Else, Default To C. If str. Drive = . There are many more things you could achieve with WMI. The onus now rests on you to ensure that you dig deeper into the world of WMI. I am attaching both project's, in zipped format, below in case you have missed a step or two. I hope you have enjoyed this article. Until next time, cheers!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |