Jump to content

Recommended Posts

Posted

Hi,

3h searching and trying several scripts here on the forum and elsewhere, and still no solution ...

I need the total cpu usage % of the machine. Nothing more. Just need to know if the machine itself is working and where between 0% to 100%. What would be the simplier/lighter solution for that ?

Cheers,

Kib

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Posted (edited)

Yes I've tried it, but can't get it smaller and it seems a hudge script to run just for one thing ?

I've answered this morning, trying to strip it down. Also can't get reliable result with it

http://www.autoitscript.com/forum/index.php?showtopic=90736&st=40&gopid=841941&#entry841941

Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Posted (edited)

Many thanks for the try !

But allways report -1 :/

I ever tested this script (found on the forum), with same result

the script is for win7 pro x64 if it is important (maybe not same dll call ?)

Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Posted (edited)

Yes confirmed, it is not x64 compatible!

I don't know how to get the CPU usage running x64 os - maybe trancexx or other geeks know it.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
Posted (edited)

  On 10/22/2010 at 4:14 PM, 'UEZ said:

Yes confirmed, it is not x64 compatible!

I don't know how to get the CPU usage running x64 os - maybe trancexx or other geeks know it.

Br,

UEZ

geeks? Structures you have in your code are messed up (from AutoIt's point of view). Starting with the first one used.

$tSYSTEM_BASIC_INFORMATION = DllStructCreate("byte Reserved1[24];" & _
            "ptr Reserved2[4];" & _
            "byte NumberOfProcessors")

    DllCall("ntdll.dll", _
            "int", "NtQuerySystemInformation", _
            "int", $SYSTEM_BASIC_INFO, _
            "ptr", DllStructGetPtr($tSYSTEM_BASIC_INFORMATION), _
            "int", DllStructGetSize($tSYSTEM_BASIC_INFORMATION), _
            "int", 0)

    $CPUCount = DllStructGetData($tSYSTEM_BASIC_INFORMATION, "NumberOfProcessors")
;...
Edited by trancexx

♡♡♡

.

eMyvnE

Posted

Thank you very much trancexx - I knew that you will solve it! The word "geek" shouldn't be negative - if this word pissed you or the others I'm sorry!

Here the modified code which should also work with x64 systems:

#include <WindowsConstants.au3>
HotKeySet("{ESC}", "_Exit")

$GUI = GUICreate("CPU Usage", 200, 25, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$iMemo = GUICtrlCreateEdit("CPU usage: ", -1, -1, 820)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUICtrlSetBkColor($iMemo, 0xFFFFFF)
GUISetState()
While 1
    MemoWrite("CPU usage: " & _GetCPUUsage() & "%")
WEnd

Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage)
EndFunc ;==>MemoWrite

Func _Exit()
    GUIDelete($GUI)
    Exit
EndFunc

Func _GetCPUUsage()
    Local Const $SYSTEM_BASIC_INFO = 0
    Local Const $SYSTEM_PERFORMANCE_INFO = 2
    Local Const $SYSTEM_TIME_INFO = 3

    Local $idletimeold = 0,$idletimediff=0, $idle
    Local $starttime = 0, $timediff = 0, $CPUCount=0

    $tSYSTEM_BASIC_INFORMATION = DllStructCreate("byte Reserved1[24];" & _
    "ptr Reserved2[4];" & _
    "byte NumberOfProcessors")

    DllCall("ntdll.dll", _
    "int", "NtQuerySystemInformation", _
    "int", $SYSTEM_BASIC_INFO, _
    "ptr", DllStructGetPtr($tSYSTEM_BASIC_INFORMATION), _
    "int", DllStructGetSize($tSYSTEM_BASIC_INFORMATION), _
    "int", 0)

    $CPUCount = DllStructGetData($tSYSTEM_BASIC_INFORMATION, "NumberOfProcessors")


    $S_SYSTEM_BASIC_INFORMATION = 0

    While 1
        Local $S_SYSTEM_PERFORMANCE_INFORMATION = DllStructCreate("int64;int[76]")
    $err = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYSTEM_PERFORMANCE_INFO, _
    "ptr", DllStructGetPtr($S_SYSTEM_PERFORMANCE_INFORMATION), _
    "int", DllStructGetSize($S_SYSTEM_PERFORMANCE_INFORMATION), _
    "int", 0)
        If $err[0] Then Return -2

        Local $S_SYSTEM_TIME_INFORMATION = DllStructCreate("int64;int64;int64;uint;int")
        $err = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", _
                "int", $SYSTEM_TIME_INFO, _
    "ptr", DllStructGetPtr($S_SYSTEM_TIME_INFORMATION), _
    "int", DllStructGetSize($S_SYSTEM_TIME_INFORMATION), _
    "int", 0)

    If $err[0] Then Return -3

    If $starttime = 0 Then
    $idletimeold = DllStructGetData($S_SYSTEM_PERFORMANCE_INFORMATION, 1)
            $starttime = DllStructGetData($S_SYSTEM_TIME_INFORMATION, 2)
            Sleep(1000)
    Else
            $idletimediff = DllStructGetData($S_SYSTEM_PERFORMANCE_INFORMATION, 1) - $idletimeold
            $timediff = DllStructGetData($S_SYSTEM_TIME_INFORMATION, 2) - $starttime

    $idle = Round(100.0 - ($idletimediff * 100.0 / $timediff)/$CPUCount,0)
    Return $idle
    EndIf
    $S_SYSTEM_PERFORMANCE_INFORMATION = 0
        $S_SYSTEM_TIME_INFORMATION = 0
    WEnd
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

  On 10/22/2010 at 7:10 PM, 'trancexx said:

geeks? Structures you have in your code are messed up (from AutoIt's point of view). Starting with the first one used.

Just for the book, that's what I wanted to say with the link above ;) ... but looking at the structures defined there, I really wonder how trancexx comes up with the definition 4 posts above :)... Lady , please enlighten me ;)...
Posted

I think trancexx has used this resource: http://msdn.microsoft.com/en-us/library/ms724509%28VS.85%29.aspx

I tried this

Func _GetCPUUsage_N()
    Local Const $SYSTEM_BASIC_INFO = 0
    Local Const $SYSTEM_PERFORMANCE_INFO = 2
    Local Const $SYSTEM_TIME_INFO = 3

    Local $idletimeold = 0, $idletimediff = 0, $idle
    Local $starttime = 0, $timediff = 0, $CPUCount = 0


    $S_SYSTEM_BASIC_INFORMATION = DllStructCreate("byte Reserved1[24];" & _
                                                 "ptr Reserved2[4];" & _
                                                 "byte NumberOfProcessors")

    DllCall("ntdll.dll", _
    "int", "NtQuerySystemInformation", _
    "int", $SYSTEM_BASIC_INFO, _
    "ptr", DllStructGetPtr($S_SYSTEM_BASIC_INFORMATION), _
    "int", DllStructGetSize($S_SYSTEM_BASIC_INFORMATION), _
    "int", 0)

    $CPUCount = DllStructGetData($S_SYSTEM_BASIC_INFORMATION, "NumberOfProcessors")


    $S_SYSTEM_BASIC_INFORMATION = 0

    While 1
        Local $S_SYSTEM_PERFORMANCE_INFORMATION = DllStructCreate("int64 IdleTime;" & _
                                                                 "int64 KernelTime;" & _
                                                                 "int64 UserTime;"& _
                                                                 "int64 Reserved1[2];"& _
                                                                 "ulong Reserved2;")
        DllCall("ntdll.dll", _
                "int", "NtQuerySystemInformation", _
                "int", $SYSTEM_PERFORMANCE_INFO, _
                "ptr", DllStructGetPtr($S_SYSTEM_PERFORMANCE_INFORMATION), _
                "int", DllStructGetSize($S_SYSTEM_PERFORMANCE_INFORMATION), _
                "int", 0)

        Local $S_SYSTEM_TIME_INFORMATION = DllStructCreate("byte Reserved1[48]")
        DllCall("ntdll.dll", _
                "int", "NtQuerySystemInformation", _
                "int", $SYSTEM_TIME_INFO, _
                "ptr", DllStructGetPtr($S_SYSTEM_TIME_INFORMATION), _
                "int", DllStructGetSize($S_SYSTEM_TIME_INFORMATION), _
                "int", 0)

    If $starttime = 0 Then
    $idletimeold = DllStructGetData($S_SYSTEM_PERFORMANCE_INFORMATION, "IdleTime")
            $starttime = DllStructGetData($S_SYSTEM_TIME_INFORMATION, 2)
            Sleep(1000)
    Else
            $idletimediff = DllStructGetData($S_SYSTEM_PERFORMANCE_INFORMATION, "IdleTime") - $idletimeold
            $timediff = DllStructGetData($S_SYSTEM_TIME_INFORMATION, 2) - $starttime

    $idle = Round(100.0 - ($idletimediff * 100.0 / $timediff) / $CPUCount, 0)
    Return $idle
    EndIf
    $S_SYSTEM_PERFORMANCE_INFORMATION = 0
        $S_SYSTEM_TIME_INFORMATION = 0
    WEnd
EndFunc

but it is not working. Help needed!

I'm too silly for that kind of stuff. ;)

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

The definitions for the structures are:

Dim $tagSYSTEM_BASIC_INFO="ulong Unk;ulong TimerResolution;ulong PhysicalPageSz;ulong NumPhysicalPages;" & _
    "ulong LowestPhysicalPageNum;ulong HighestPhysicalPageNum;ulong AllocationGranularity;" & _
    "ptr LowestUserAddress;ptr HighestUserAddress;ulong_ptr ActiveProcessorAffinityMask"

If @AutoItX64 Then
    $tagSYSTEM_BASIC_INFO&=";ulong NumProcessors"
Else
    $tagSYSTEM_BASIC_INFO&=";byte NumProcessors"
Endif

Dim $tagSYSTEM_PERF_INFO="int64 IdleTime;int64 ReadXferCount;int64 WriteXferCount;int64 OtherXferCount;ulong ReadOperationCount;ulong WriteOperationCount;" & _
    "ulong OtherOperationCount;ulong AvailablePages;ulong TotalCommittedPages;ulong TotalCommitLimit;ulong PeakCommitment;ulong PageFaults;ulong WriteCopyFaults;" & _
    "ulong TransitionFaults;ulong Reserved1;ulong DemandZeroFaults;ulong PagesRead;ulong PageReadIOs;ulong Reserved2[2];ulong PageFilePagesWritten;ulong PFPageWriteIOs;" & _
    "ulong MappedFilePagesWritten;ulong MFPageIOs;ulong PagedPoolUsage;ulong NonPagedPoolUsage;ulong PagedPoolAllocs;ulong PagedPoolFrees;" & _
    "ulong NonPagedPoolAllocs;ulong NonPagedPoolFrees;ulong TotalFreeSystemPtes;ulong SystemCodePage;ulong TotalSysDriverPages;ulong TotalSysCodePages;" & _
    "ulong SmallNonPagedLookasideListAllocHits;ulong SmallPagedLookasideListAllocHits;ulong Reserved3;ulong MmSystemCachePage;ulong PagedPoolPage;" & _
    "ulong SysDriverPage;ulong FastReadNoWait;ulong FastReadWait;ulong FastReadResourceMiss;ulong FastReadNotPossible;ulong FastMdlReadNoWait;ulong FastMdlReadWait;" & _
    "ulong FastMdlReadResourceMiss;ulong FastMdlReadNotPossible;ulong MapDataNoWait;ulong MapDataWait;ulong MapDataNoWaitMiss;ulong MapDataWaitMiss;" & _
    "ulong PinMappedDataCount;ulong PinReadNoWait;ulong PinReadWait;ulong PinReadNoWaitMiss;ulong PinReadWaitMiss;ulong CopyReadNoWait;ulong CopyReadWait;" & _
    "ulong CopyReadNoWaitMiss;ulong CopyReadWaitMiss;ulong MdlReadNoWait;ulong MdlReadWait;ulong MdlReadNoWaitMiss;ulong MdlReadWaitMiss;ulong ReadAheadIOs;" & _
    "ulong LazyWriteIOs;ulong LazyWritePages;ulong DataFlushes;ulong DataPages;ulong ContextSwitches;ulong FirstLevelTbFills;ulong SecondLevelTbFills;ulong SystemCalls"

*edit: had ubyte instead of byte

Edited by Ascend4nt

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted (edited)

By the way Information Class 3 is TimeOfDay, and not SystemTimeInfo.

That definition is:

$tagSYSTEM_TIME_OF_DAY="int64 BootTime;int64 CurrentTime;int64 TimeZoneBias;ulong CurrentTimeZoneId"

If you want information for Idle/Kernel/User time for the CPU's, you'll need to use information class 8 (SystemProcessorTimes).

The return of that call will be an array of structures (total is equal to the CPU count), each with this format:

Dim $tagSYSTEM_PROCESSOR_TIMES="int64 IdleTime;int64 KernelTime;int64 UserTime;int64 DpcTime;int64 InterruptTime;ulong InterruptCount"

(note the last value may be ulong_ptr on both - I haven't tested them out).

Also - you can use GetSystemInfo or GetNativeSystemInfo to get the CPU count, you don't need to go the undocumented route for that.

All in all - its just plain better to use my Performance Counters UDF ;) Quicker, easier, and simpler.

*edit: AutoIt tags

Edited by Ascend4nt

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted (edited)

  On 10/22/2010 at 10:49 PM, 'Ascend4nt said:

The definitions for the structures are:

Dim $tagSYSTEM_BASIC_INFO="ulong Unk;ulong TimerResolution;ulong PhysicalPageSz;ulong NumPhysicalPages;" & _
    "ulong LowestPhysicalPageNum;ulong HighestPhysicalPageNum;ulong AllocationGranularity;" & _
    "ptr LowestUserAddress;ptr HighestUserAddress;ulong_ptr ActiveProcessorAffinityMask"

If @AutoItX64 Then
    $tagSYSTEM_BASIC_INFO&=";ulong NumProcessors"
Else
    $tagSYSTEM_BASIC_INFO&=";byte NumProcessors"
Endif

Dim $tagSYSTEM_PERF_INFO="int64 IdleTime;int64 ReadXferCount;int64 WriteXferCount;int64 OtherXferCount;ulong ReadOperationCount;ulong WriteOperationCount;" & _
    "ulong OtherOperationCount;ulong AvailablePages;ulong TotalCommittedPages;ulong TotalCommitLimit;ulong PeakCommitment;ulong PageFaults;ulong WriteCopyFaults;" & _
    "ulong TransitionFaults;ulong Reserved1;ulong DemandZeroFaults;ulong PagesRead;ulong PageReadIOs;ulong Reserved2[2];ulong PageFilePagesWritten;ulong PFPageWriteIOs;" & _
    "ulong MappedFilePagesWritten;ulong MFPageIOs;ulong PagedPoolUsage;ulong NonPagedPoolUsage;ulong PagedPoolAllocs;ulong PagedPoolFrees;" & _
    "ulong NonPagedPoolAllocs;ulong NonPagedPoolFrees;ulong TotalFreeSystemPtes;ulong SystemCodePage;ulong TotalSysDriverPages;ulong TotalSysCodePages;" & _
    "ulong SmallNonPagedLookasideListAllocHits;ulong SmallPagedLookasideListAllocHits;ulong Reserved3;ulong MmSystemCachePage;ulong PagedPoolPage;" & _
    "ulong SysDriverPage;ulong FastReadNoWait;ulong FastReadWait;ulong FastReadResourceMiss;ulong FastReadNotPossible;ulong FastMdlReadNoWait;ulong FastMdlReadWait;" & _
    "ulong FastMdlReadResourceMiss;ulong FastMdlReadNotPossible;ulong MapDataNoWait;ulong MapDataWait;ulong MapDataNoWaitMiss;ulong MapDataWaitMiss;" & _
    "ulong PinMappedDataCount;ulong PinReadNoWait;ulong PinReadWait;ulong PinReadNoWaitMiss;ulong PinReadWaitMiss;ulong CopyReadNoWait;ulong CopyReadWait;" & _
    "ulong CopyReadNoWaitMiss;ulong CopyReadWaitMiss;ulong MdlReadNoWait;ulong MdlReadWait;ulong MdlReadNoWaitMiss;ulong MdlReadWaitMiss;ulong ReadAheadIOs;" & _
    "ulong LazyWriteIOs;ulong LazyWritePages;ulong DataFlushes;ulong DataPages;ulong ContextSwitches;ulong FirstLevelTbFills;ulong SecondLevelTbFills;ulong SystemCalls"

*edit: had ubyte instead of byte

Definitions are constructed by free interpretation of the unions. Those that you posted too.

$tagSYSTEM_PERF_INFO have additional system specific elements.

This could be UEZ's function written to check for that.

#include <WindowsConstants.au3>
#include "AutoItObject.au3"

HotKeySet("{ESC}", "_Exit")
_AutoItObject_Startup()


Global $GUI = GUICreate("CPU Usage", 200, 25, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
Global $iMemo = GUICtrlCreateEdit("CPU usage: ", -1, -1, 820)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUICtrlSetBkColor($iMemo, 0xFFFFFF)
GUISetState()

While 1
    MemoWrite("CPU usage: " & _GetCPUUsage() & "%")
WEnd

Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage)
EndFunc   ;==>MemoWrite

Func _Exit()
    GUIDelete($GUI)
    Exit
EndFunc   ;==>_Exit

Func _GetCPUUsage()
    Local Const $SYSTEM_BASIC_INFO = 0
    Local Const $SYSTEM_PERFORMANCE_INFO = 2
    Local Const $SYSTEM_TIMEOFDAY_INFO = 3

    Local $iIdleTime = 0, $iIdleTimeDiff = 0
    Local $iStartTime = 0, $iTimeDiff = 0

    Local $tSYSTEM_BASIC_INFORMATION = _AutoItObject_DllStructCreate("byte Reserved1[24];" & _
            "ptr Reserved2[4];" & _
            "byte NumberOfProcessors")

    Local $aCall = DllCall("ntdll.dll", "long", "NtQuerySystemInformation", _
            "int", $SYSTEM_BASIC_INFO, _
            "ptr", $tSYSTEM_BASIC_INFORMATION(), _
            "dword", $tSYSTEM_BASIC_INFORMATION.__size__, _
            "dword*", 0)

    Local $iCPUCount = $tSYSTEM_BASIC_INFORMATION.NumberOfProcessors

    Local $tagSYSTEM_PERFORMANCE_INFORMATION = "int64 IdleTime; byte OtherData[304];"
    Local $tSYSTEM_PERFORMANCE_INFORMATION = _AutoItObject_DllStructCreate($tagSYSTEM_PERFORMANCE_INFORMATION)

    Local $tSYSTEM_TIMEOFDAY_INFORMATION = _AutoItObject_DllStructCreate("int64 BootTime;" & _
            "int64 SystemTime;" & _
            "int64 ExpTimeZoneBias;" & _
            "dword CurrentTimeZoneId;" & _
            "dword Reserved;")

    While 1
        $aCall = DllCall("ntdll.dll", "long", "NtQuerySystemInformation", _
                "dword", $SYSTEM_PERFORMANCE_INFO, _
                "ptr", 0, _
                "dword", 0, _
                "dword*", 0)
        If @error Then Return SetError(1, 0, -1)

        If $aCall[4] > $tSYSTEM_PERFORMANCE_INFORMATION.__size__ Then
            ; Redefine $tSYSTEM_PERFORMANCE_INFORMATION to one with proper size. That would be $aCall[4]
            Local $iSizeDiff = $aCall[4] - $tSYSTEM_PERFORMANCE_INFORMATION.__size__
            $tagSYSTEM_PERFORMANCE_INFORMATION &= "byte SystemSpecific[" & $iSizeDiff & "];"
            $tSYSTEM_PERFORMANCE_INFORMATION = _AutoItObject_DllStructCreate($tagSYSTEM_PERFORMANCE_INFORMATION)
        EndIf

        $aCall = DllCall("ntdll.dll", "long", "NtQuerySystemInformation", _
                "dword", $SYSTEM_PERFORMANCE_INFO, _
                "ptr", $tSYSTEM_PERFORMANCE_INFORMATION(), _
                "dword", $tSYSTEM_PERFORMANCE_INFORMATION.__size__, _
                "dword*", 0)
        If @error Then Return SetError(2, 0, -1)

        $aCall = DllCall("ntdll.dll", "long", "NtQuerySystemInformation", _
                "dword", $SYSTEM_TIMEOFDAY_INFO, _
                "ptr", $tSYSTEM_TIMEOFDAY_INFORMATION(), _
                "dword", $tSYSTEM_TIMEOFDAY_INFORMATION.__size__, _
                "dword*", 0)
        If @error Then Return SetError(3, 0, -1)

        If $iStartTime Then
            $iIdleTimeDiff = $tSYSTEM_PERFORMANCE_INFORMATION.IdleTime - $iIdleTime
            $iTimeDiff = $tSYSTEM_TIMEOFDAY_INFORMATION.SystemTime - $iStartTime
            Return Round(100 - ($iIdleTimeDiff * 100 / $iTimeDiff) / $iCPUCount, 0)
        Else
            $iIdleTime = $tSYSTEM_PERFORMANCE_INFORMATION.IdleTime
            $iStartTime = $tSYSTEM_TIMEOFDAY_INFORMATION.SystemTime
            Sleep(1000)
        EndIf
    WEnd
EndFunc   ;==>_GetCPUUsage
Edited by trancexx

♡♡♡

.

eMyvnE

Posted

  On 10/23/2010 at 12:09 AM, 'trancexx said:

Definitions are constructed by free interpretation of the unions. Those that you posted too.

Excuse me? That comes straight from the Windows NT/2000 Native API Reference. No free interpretation there. And no unions.

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...