Results 1 to 17 of 17

Thread: For fnajar (Re: CPU Info)

  1. #1

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    For fnajar (Re: CPU Info)

    Sorry couldn'r post to that thread, so here it is:

    You can use WMI (Windows Management Interface). Add a ListBox (lstCPU), a textbox (txtCPU - make it multiline and high enough to see multiple lines) and a label (lblTitle) to your form. Add a reference to Microsoft WMI Scripting Library. If you dont have it installed,
    Download WMI SDK from MSDN

    VB Code:
    1. Option Explicit
    2. Private m_arrCPU() As String
    3. Private m_objCPUSet As SWbemObjectSet
    4. Private m_objWMINameSpace As SWbemServices
    5.  
    6.  
    7.  
    8.  
    9. Private Sub Form_Load()
    10.     Dim objCPU As SWbemObject 'WMI Object
    11.     Dim strPath As String
    12.     Dim strCaption As String
    13.     Dim lngElement As Long
    14.    
    15.     ReDim m_arrCPU(0) As String
    16.  
    17.     On Error GoTo ErrorHandler
    18.  
    19.     Set m_objWMINameSpace = GetObject("winmgmts:")
    20.     lstCPU.Clear
    21.  
    22.  
    23.     Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
    24.    
    25.     strCaption = m_objCPUSet.Count & " processor"
    26.     If m_objCPUSet.Count <> 1 Then strCaption = strCaption & "s"
    27.     strCaption = strCaption & " detected on this machine"
    28.     lblTitle.Caption = strCaption
    29.                
    30.     For Each objCPU In m_objCPUSet
    31.         With objCPU
    32.             strPath = .Path_ & ""
    33.             If strPath <> "" Then
    34.                 lstCPU.AddItem .Name
    35.                 'save path to array, in case the machine has multiple CPUs,
    36.                 'each can be identified and their info loaded if needed
    37.                
    38.                 lngElement = IIf(m_arrCPU(0) = "", 0, UBound(m_arrCPU) + 1)
    39.                 ReDim Preserve m_arrCPU(lngElement) As String
    40.                 m_arrCPU(lngElement) = strPath
    41.             End If
    42.         End With
    43.     Next
    44.     If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0
    45.      
    46. ExitProc:
    47.     Set objCPU = Nothing
    48.  
    49.     Exit Sub
    50.  
    51. ErrorHandler:
    52.     MsgBox "CPU Information could not be displayed." & vbCrLf & Err.Description, , "Error"
    53.     Resume ExitProc
    54. End Sub
    55.  
    56. Private Sub Form_Unload(Cancel As Integer)
    57.     Set m_objCPUSet = Nothing
    58.     Set m_objWMINameSpace = Nothing
    59. End Sub
    60.  
    61. Private Sub lstCPU_Click()
    62.     Dim objCPU As SWbemObject
    63.     Dim strInfo As String
    64.  
    65.     On Error Resume Next
    66.  
    67.     Set objCPU = m_objCPUSet(m_arrCPU(lstCPU.ListIndex))
    68.     With objCPU
    69.         strInfo = "Description: " & .Description & vbCrLf
    70.         strInfo = strInfo & "Processor ID: " & .ProcessorID & vbCrLf
    71.         strInfo = strInfo & "Status: " & .Status & vbCrLf
    72.         strInfo = strInfo & "Manufacturer: " & .Manufacturer & vbCrLf
    73.         strInfo = strInfo & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
    74.         strInfo = strInfo & "Load Percentage: " & .LoadPercentage & vbCrLf
    75.         strInfo = strInfo & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
    76.         strInfo = strInfo & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
    77.         strInfo = strInfo & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
    78.         strInfo = strInfo & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
    79.         strInfo = strInfo & "Power Management Supported: " & .PowerManagementSupported
    80.     End With
    81.     txtCpu.Text = strInfo
    82. End Sub
    83.  
    84. Private Function AvailabilityToString(p_intCode As Integer) As String
    85.     Dim strReturn As String
    86.    
    87.     'These return p_intCodes are based on WMI SDK Documentation
    88.    
    89.     Select Case p_intCode
    90.         Case 1, 2
    91.             strReturn = "Unknown"
    92.         Case 3
    93.             strReturn = "Running/Full Power"
    94.         Case 4
    95.             strReturn = "Warning"
    96.         Case 5
    97.             strReturn = "In Test"
    98.         Case 6
    99.             strReturn = "Not Applicable"
    100.         Case 7
    101.             strReturn = "Power Off"
    102.         Case 8
    103.             strReturn = "Off Line"
    104.         Case 9
    105.             strReturn = "Off Duty"
    106.         Case 10
    107.             strReturn = "Degraded"
    108.         Case 11
    109.             strReturn = "Not Installed"
    110.         Case 12
    111.             strReturn = "Install Error"
    112.         Case 13
    113.             strReturn = "Power Save - Unknown"
    114.         Case 14
    115.             strReturn = "Power Save - Low Power Mode"
    116.         Case 15
    117.             strReturn = "Power Save - Standby"
    118.         Case 16
    119.             strReturn = "Power Cycle"
    120.         Case 17
    121.             strReturn = "Power Save - Warning"
    122.         Case Else
    123.             strReturn = "Unknown"
    124.     End Select
    125.     AvailabilityToString = strReturn
    126. End Function
    Regards,

  2. #2
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    I agree y ou can use wmi and adsi, but if it's not installed you would have to download it from MS. They are installed on w2k by default. I posted a sample app there for him.

  3. #3
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Serge by the way what is the post count to change your description. I thought that it was 4096 or somethig like that.

  4. #4
    He's a mod, he can change it at will.

  5. #5
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    ah i see. that's why i was wondering. Thanks filburt1. Hows hefer and rocko.

  6. #6
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    download page says W2K is required ... bummer

  7. #7
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    You can download it for NT/98 from MS site.

  8. #8
    Originally posted by jjortiz
    ah i see. that's why i was wondering. Thanks filburt1. Hows hefer and rocko.
    Still fat and still has that house in O-Town.

  9. #9
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    I watch it with my kids. Just funny that hefers family is a bunch of wolves. That is cartoons at it's best.

  10. #10
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Windows Management Instrumentation (WMI) SDK

    Software Requirements

    Microsoft Windows 2000 or Windows NT® 4.0
    Microsoft Internet Explorer version 5 or laterHardware

  11. #11
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Really so how is it that NetIQ uses WMI and it see's WinNT servers.

  12. #12

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    For people with other then NT/2000
    Download from here

  13. #13
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Thank you serge for backing that up. I know that i have worded my last couple of post kinda wrong.

  14. #14
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    The requirements listed were from the MS site listed at the beginning of this thread. Downloading the WMI, Win 95/98/NT version now.

    And yes jjortiz, you need to relax and have a beer or some-such.

  15. #15
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    You know i constantly have to apologize for my attitude. We are just talking. please do not misunderstand me. If you guys met me you would automatically know that i rarely get in a bad mood. So here it goes sorry.

  16. #16
    Member
    Join Date
    Jan 2002
    Posts
    35

    Smile

    thanks

  17. #17
    Lively Member
    Join Date
    Nov 2000
    Location
    Posts
    124
    I have tried the example, it works for my old PC. But when I tried to use it on P4 and the latest laptops with Intel mobile processor, the result obtained was not correct. Is there any update I need to download ?

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