Jump to content
Sign in to follow this  
Possessed

Two problems here...

Recommended Posts

Possessed

Hello all I need help once again with 2 things like the title says. first how would i go about getting CPU usage I do have this old autoit file called Computerinfo.au3 kicking around but dont have a clue how to use it in my little program I am making. Also my other problem is that I would like to have a chunk of code in my program that would only let it run 1 time. Thanks for your help guys and gals.

Here is the func that is in the "Computerinfo.au3" Author: Jarvis J. Stubblefield (JSThePatriot) http://www.vortexrevolutions.com/

Func _ComputerGetProcessors(ByRef $aProcessorInfo)
    Local $colItems, $objWMIService, $objItem
    Dim $aProcessorInfo[1][42], $i = 1
    
    $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) Then
        For $objItem In $colItems
            ReDim $aProcessorInfo[UBound($aProcessorInfo) + 1][42]
            $aProcessorInfo[$i][0]  = StringStripWS($objItem.Name, 1)
            $aProcessorInfo[$i][1]  = $objItem.AddressWidth
            $aProcessorInfo[$i][2]  = $objItem.Architecture
            $aProcessorInfo[$i][3]  = $objItem.Availability
            $aProcessorInfo[$i][4]  = $objItem.Description
            $aProcessorInfo[$i][5]  = $objItem.ConfigManagerErrorCode
            $aProcessorInfo[$i][6]  = $objItem.ConfigManagerUserConfig
            $aProcessorInfo[$i][7]  = $objItem.CpuStatus
            $aProcessorInfo[$i][8]  = $objItem.CreationClassName
            $aProcessorInfo[$i][9]  = $objItem.CurrentClockSpeed
            $aProcessorInfo[$i][10] = $objItem.CurrentVoltage
            $aProcessorInfo[$i][11] = $objItem.DataWidth
            $aProcessorInfo[$i][12] = $objItem.DeviceID
            $aProcessorInfo[$i][13] = $objItem.ErrorCleared
            $aProcessorInfo[$i][14] = $objItem.ErrorDescription
            $aProcessorInfo[$i][15] = $objItem.ExtClock
            $aProcessorInfo[$i][16] = $objItem.Family
            $aProcessorInfo[$i][17] = $objItem.L2CacheSize
            $aProcessorInfo[$i][18] = $objItem.L2CacheSpeed
            $aProcessorInfo[$i][19] = $objItem.LastErrorCode
            $aProcessorInfo[$i][20] = $objItem.Level
            $aProcessorInfo[$i][21] = $objItem.LoadPercentage
            $aProcessorInfo[$i][22] = $objItem.Manufacturer
            $aProcessorInfo[$i][23] = $objItem.MaxClockSpeed
            $aProcessorInfo[$i][24] = $objItem.OtherFamilyDescription
            $aProcessorInfo[$i][25] = $objItem.PNPDeviceID
            $aProcessorInfo[$i][26] = $objItem.PowerManagementCapabilities(0)
            $aProcessorInfo[$i][27] = $objItem.PowerManagementSupported
            $aProcessorInfo[$i][28] = $objItem.ProcessorId
            $aProcessorInfo[$i][29] = $objItem.ProcessorType
            $aProcessorInfo[$i][30] = $objItem.Revision
            $aProcessorInfo[$i][31] = $objItem.Role
            $aProcessorInfo[$i][32] = $objItem.SocketDesignation
            $aProcessorInfo[$i][33] = $objItem.Status
            $aProcessorInfo[$i][34] = $objItem.StatusInfo
            $aProcessorInfo[$i][35] = $objItem.Stepping
            $aProcessorInfo[$i][36] = $objItem.SystemCreationClassName
            $aProcessorInfo[$i][37] = $objItem.SystemName
            $aProcessorInfo[$i][38] = $objItem.UniqueId
            $aProcessorInfo[$i][39] = $objItem.UpgradeMethod
            $aProcessorInfo[$i][40] = $objItem.Version
            $aProcessorInfo[$i][41] = $objItem.VoltageCaps
            $i += 1
        Next
        $aProcessorInfo[0][0] = UBound($aProcessorInfo) - 1
        If $aProcessorInfo[0][0] < 1 Then
            SetError(1, 1, 0)
        EndIf
    Else
        SetError(1, 2, 0)
    EndIf
EndFunc;_ComputerGetProcessors

Share this post


Link to post
Share on other sites
sandman

Hello all I need help once again with 2 things like the title says. first how would i go about getting CPU usage I do have this old autoit file called Computerinfo.au3 kicking around but dont have a clue how to use it in my little program I am making. Also my other problem is that I would like to have a chunk of code in my program that would only let it run 1 time. Thanks for your help guys and gals.

Here is the func that is in the "Computerinfo.au3" Author: Jarvis J. Stubblefield (JSThePatriot) http://www.vortexrevolutions.com/

Func _ComputerGetProcessors(ByRef $aProcessorInfo)
    Local $colItems, $objWMIService, $objItem
    Dim $aProcessorInfo[1][42], $i = 1
    
    $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
    If IsObj($colItems) Then
        For $objItem In $colItems
            ReDim $aProcessorInfo[UBound($aProcessorInfo) + 1][42]
            $aProcessorInfo[$i][0]  = StringStripWS($objItem.Name, 1)
            $aProcessorInfo[$i][1]  = $objItem.AddressWidth
            $aProcessorInfo[$i][2]  = $objItem.Architecture
            $aProcessorInfo[$i][3]  = $objItem.Availability
            $aProcessorInfo[$i][4]  = $objItem.Description
            $aProcessorInfo[$i][5]  = $objItem.ConfigManagerErrorCode
            $aProcessorInfo[$i][6]  = $objItem.ConfigManagerUserConfig
            $aProcessorInfo[$i][7]  = $objItem.CpuStatus
            $aProcessorInfo[$i][8]  = $objItem.CreationClassName
            $aProcessorInfo[$i][9]  = $objItem.CurrentClockSpeed
            $aProcessorInfo[$i][10] = $objItem.CurrentVoltage
            $aProcessorInfo[$i][11] = $objItem.DataWidth
            $aProcessorInfo[$i][12] = $objItem.DeviceID
            $aProcessorInfo[$i][13] = $objItem.ErrorCleared
            $aProcessorInfo[$i][14] = $objItem.ErrorDescription
            $aProcessorInfo[$i][15] = $objItem.ExtClock
            $aProcessorInfo[$i][16] = $objItem.Family
            $aProcessorInfo[$i][17] = $objItem.L2CacheSize
            $aProcessorInfo[$i][18] = $objItem.L2CacheSpeed
            $aProcessorInfo[$i][19] = $objItem.LastErrorCode
            $aProcessorInfo[$i][20] = $objItem.Level
            $aProcessorInfo[$i][21] = $objItem.LoadPercentage
            $aProcessorInfo[$i][22] = $objItem.Manufacturer
            $aProcessorInfo[$i][23] = $objItem.MaxClockSpeed
            $aProcessorInfo[$i][24] = $objItem.OtherFamilyDescription
            $aProcessorInfo[$i][25] = $objItem.PNPDeviceID
            $aProcessorInfo[$i][26] = $objItem.PowerManagementCapabilities(0)
            $aProcessorInfo[$i][27] = $objItem.PowerManagementSupported
            $aProcessorInfo[$i][28] = $objItem.ProcessorId
            $aProcessorInfo[$i][29] = $objItem.ProcessorType
            $aProcessorInfo[$i][30] = $objItem.Revision
            $aProcessorInfo[$i][31] = $objItem.Role
            $aProcessorInfo[$i][32] = $objItem.SocketDesignation
            $aProcessorInfo[$i][33] = $objItem.Status
            $aProcessorInfo[$i][34] = $objItem.StatusInfo
            $aProcessorInfo[$i][35] = $objItem.Stepping
            $aProcessorInfo[$i][36] = $objItem.SystemCreationClassName
            $aProcessorInfo[$i][37] = $objItem.SystemName
            $aProcessorInfo[$i][38] = $objItem.UniqueId
            $aProcessorInfo[$i][39] = $objItem.UpgradeMethod
            $aProcessorInfo[$i][40] = $objItem.Version
            $aProcessorInfo[$i][41] = $objItem.VoltageCaps
            $i += 1
        Next
        $aProcessorInfo[0][0] = UBound($aProcessorInfo) - 1
        If $aProcessorInfo[0][0] < 1 Then
            SetError(1, 1, 0)
        EndIf
    Else
        SetError(1, 2, 0)
    EndIf
EndFunc;_ComputerGetProcessors
To have this run only one time, put a Func() around the whole program. Then make a While() thing like this:

While 1
   Call("YourFuncName")
   $a = 1
   Select
     Case $msg = $GUI_EVENT_CLOSE
       $a = 0
   EndSelect
   If $a = 0 Then
       Exit
   EndIf
WEnd

That should work.. sorry but I had to rush a bit on this.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites
Possessed

sorry man you didnt read my post right but thanks for trying.

Edited by Possessed

Share this post


Link to post
Share on other sites
Possessed

~Bump

Plz can anyone help me?

Share this post


Link to post
Share on other sites
SmOke_N

~Bump

Plz can anyone help me?

The first question, If I had to guess:
MsgBox(0, '', _ComputerGetLoad() & '%')
Func _ComputerGetLoad()
    Local $colItems, $objWMIService, $objItem
    $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            If $objItem.LoadPercentage Then Return $objItem.LoadPercentage
        Next
        Return SetError(1, 0, '')   
    EndIf
    Return SetError(1, 0, '')
EndFunc

The second question, look at _SingleTon() in the help file.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Possessed

Thank you SmOke_N your always the one who can help me :whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×