Results 1 to 10 of 10

Thread: [RESOLVED] Get System Hardware Info

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    [RESOLVED] Get System Hardware Info

    I would have thought this was easy, but I can't find it. I need to find out what hardware the system has. For example CPU, ram, and harddrive. Is there any way to do this?

    Thanks
    Last edited by mpdeglau; Oct 14th, 2005 at 01:52 PM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Get System Hardware Info

    Update:
    Ok I found I can get most, maybe even all of my information using System.Management. My question now is how can I figure out what tables I can query. Table may be the wrong turm but since this is like an SQL query I'm not sure what to call it. But I can search using SELECT * FROM Win32_OperatingSystem. Anyone know where I can look to find all the available options for Win32_...
    Thanks

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Get System Hardware Info

    Update:
    Found it. The 101 examples has it.

  4. #4
    Member
    Join Date
    Aug 2005
    Location
    Santo Domingo, Dominican Republic
    Posts
    43

    Re: [RESOLVED] Get System Hardware Info

    mpdeglau could u post the code here?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [RESOLVED] Get System Hardware Info

    What are you looking for?

  6. #6
    Member
    Join Date
    Aug 2005
    Location
    Santo Domingo, Dominican Republic
    Posts
    43

    Post Re: [RESOLVED] Get System Hardware Info

    I Have to develop One of Each of the next 3 Categories.

    Cat A (Files And Programs):
    1. Get the Number Of Times a Specific Program has been used, and the time it was used.
    2. Get The Content Details of a Specific Directory or Sub-Directory (Folders)
    3. See All Hidden Files in a Specific Directory.
    4. Hide All Files from an Specific Extension in a Directory

    Cat B (HardDisk):
    1. Get The Free and Ocupied Space of a HD
    2. See How Many EXE files have been eliminated from a HD in a Specific Period Of Time
    3. See All Content of a HD by File Type
    4. Determine How Many times a HD has been desfragmented

    Cat C (Remote Conexion and Internet):
    1. Remotly Check the existence of a Floppy Disk or a CD in a PC
    2. Limit the File Types that can be downloaded from Internet
    3. Limit the File Size that can be downloaded from Internet
    4. Get the most visited WebSites by an User

    If Someone Can help me in AT LEAST one i will really really appreciate it
    Last edited by loudbliss; Oct 14th, 2005 at 03:23 PM. Reason: syntax

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [RESOLVED] Get System Hardware Info

    Here is code to get the hard drive size and the free space. You need to add a reference to System.Management. You will have a much easier time if you download and install the vb.net 101 examples. There are a ton of classes you can use in the query. Install it to any folder you want then search that folder for WMI and it will show you the example project for this.

    VB Code:
    1. Imports System.Managment
    2.  
    3. Public Class Class1
    4.   Private HDToGet as String   'the drive you want to get the size of
    5.   Private _HDSize as string
    6.   Private _HDFreeSpace
    7.  
    8.   Public Sub New()
    9.  
    10.   End Sub
    11.   Public Sub New(specificHD as string)  'sets the drive to get the size
    12.      HDToGet = SpecificHD
    13.   End Sub
    14.  
    15.     Public Property HDSize() As String
    16.         Get
    17.             getHardDriveTotalSpace(CaptureDrive)
    18.             Return _HDSize
    19.         End Get
    20.         Set(ByVal Value As String)
    21.             _HDSize = Value
    22.         End Set
    23.     End Property
    24.  
    25.     Public Property HDFreeSpace() As String
    26.         Get
    27.             getHardDriveFreeSpace(CaptureDrive)
    28.             Return _HDFreeSpace
    29.         End Get
    30.         Set(ByVal Value As String)
    31.             _HDFreeSpace = Value
    32.         End Set
    33.     End Property
    34.  
    35.     Private Function getHardDriveTotalSpace(ByVal capDrive As String) As String
    36.         Dim HDSize As String
    37.  
    38.         Dim objOS = New ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
    39.         Dim objMgmt As ManagementObject
    40.  
    41.         For Each objMgmt In objOS.Get
    42.             If objMgmt("Name").ToString = capDrive Then
    43.                 HDSize = objMgmt("Size").ToString
    44.             End If
    45.         Next
    46.         _HardDriveSize = Format(HDSize / 1073741824, "0.00")
    47.     End Function
    48.  
    49.     Private Function getHardDriveFreeSpace(ByVal capDrive As String) As String
    50.         Dim HDSpace As String
    51.  
    52.         Dim objOS = New ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
    53.         Dim objMgmt As ManagementObject
    54.  
    55.         For Each objMgmt In objOS.Get
    56.             If objMgmt("Name").ToString = capDrive Then
    57.                 HDSpace = objMgmt("FreeSpace").ToString
    58.             End If
    59.         Next
    60.         _HDFreeSpace = Format(HDSpace / 1073741824, "0.00")
    61.     End Function
    62. End Class

  8. #8
    Member
    Join Date
    Aug 2005
    Location
    Santo Domingo, Dominican Republic
    Posts
    43

    Re: [RESOLVED] Get System Hardware Info

    mpdeglau thx very much man
    let me see now how that 101 examples work

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] Get System Hardware Info

    Download Scriptomatic2 by the Microsoft team. It writes VBS as well as other languages to easily use WMI. It also emumerates all available options that you select from combo boxes.

  10. #10
    Member
    Join Date
    Aug 2005
    Location
    Santo Domingo, Dominican Republic
    Posts
    43

    Resolved Re: [RESOLVED] Get System Hardware Info

    mpdeglau
    i used your code and it was very very helpful, it just had a couple of errors therefore im going to post the corrected code (the error where in variables and meaningless stuffs like that)


    VB Code:
    1. Imports System.Management
    2.  
    3. Public Class Class1
    4.     Private HDToGet As String   'the drive you want to get the size of
    5.     Private _HDFreeSpace As String
    6.     Private _HardDriveSize As String
    7.  
    8.     Public Sub New(ByVal specificHD As String) 'sets the drive to get the size
    9.         HDToGet = specificHD
    10.     End Sub
    11.  
    12.     Public Property HDSize() As String
    13.         Get
    14.             getHardDriveTotalSpace(HDToGet)
    15.             Return _HardDriveSize
    16.         End Get
    17.         Set(ByVal Value As String)
    18.             _HardDriveSize = Value
    19.         End Set
    20.     End Property
    21.  
    22.     Public Property HDFreeSpace() As String
    23.         Get
    24.             getHardDriveFreeSpace(HDToGet)
    25.             Return _HDFreeSpace
    26.         End Get
    27.         Set(ByVal Value As String)
    28.             _HDFreeSpace = Value
    29.         End Set
    30.     End Property
    31.  
    32.     Private Function getHardDriveTotalSpace(ByVal capDrive As String) As String
    33.         Dim HDSize As String
    34.  
    35.         Dim objOS = New ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
    36.         Dim objMgmt As ManagementObject
    37.  
    38.         For Each objMgmt In objOS.Get
    39.             If objMgmt("Name").ToString = capDrive Then
    40.                 HDSize = objMgmt("Size").ToString
    41.             End If
    42.         Next
    43.         _HardDriveSize = Format(HDSize / 1073741824, "0.00")
    44.     End Function
    45.  
    46.     Private Function getHardDriveFreeSpace(ByVal capDrive As String) As String
    47.         Dim HDSpace As String
    48.  
    49.         Dim objOS = New ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
    50.         Dim objMgmt As ManagementObject
    51.  
    52.         For Each objMgmt In objOS.Get
    53.             If objMgmt("Name").ToString = capDrive Then
    54.                 HDSpace = objMgmt("FreeSpace").ToString
    55.             End If
    56.         Next
    57.         _HDFreeSpace = Format(HDSpace / 1073741824, "0.00")
    58.     End Function
    59. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width