Ich habe es als 32bit kompiliert und es bringt wie gesagt garkeine Werte.
Edit: Ok jetzt gehts, wenn man calc.exe vorher aufruft. Mein Fehler. Allerdings stimmt keiner dieser Werte auch nur annähernd mit dem überein den der Taskmanager anzeigt.
Ich habe es als 32bit kompiliert und es bringt wie gesagt garkeine Werte.
Edit: Ok jetzt gehts, wenn man calc.exe vorher aufruft. Mein Fehler. Allerdings stimmt keiner dieser Werte auch nur annähernd mit dem überein den der Taskmanager anzeigt.
Existiert auch ein Prozess namens calc.exe?
Ich habe hier auch Win7 x64 vor mir und als 32Bit kompiliert funktioniert es (natürlich nur wenn der Prozess calc.exe existiert).
Edit: ...
Ja das war mein Fehler habs oben noch editiert gehabt. Allerdings stimmt keiner der angezeigten Werte auch nur annähernd mit dem überein den der Taskmanager anzeigt. Der Taskmanager sagt 5005 das was am nächsten dran kommt ist PeakPagefielUsage mi 6448
Edit: Hab nun das von UEZ und das von AspirinJunkie untern Win 7 x86 getestet beides mit dem selben Ergebniss wie unter Win 7 x64.
AspirinJunkie keine Ahnung warum es bei dir geht. Bei mir geht es auf vier verschiedenen Win 7 x64 Rechnern und einem Win 7 x86 Rechner nicht.
Der Taskmanager von Win7 zeigt standardmäßig den Wert "Private Working Set" an.
Dieser wird nicht durch die Lösungen hier angezeigt.
Man muss also eine Lösung finden wie man an diesen Wert gelangt.
Kann damit vielleicht jemand was Anfangen, da wirs gezeigt wie man eben diesen Wert für Win 7 berechnet. Kann aber selber damit nicht wirklich viel anfangen: http://processlasso.blogspot.com/2009/09/calcul…g-set-size.html
Mal eine kurze Zwischenfrage: Wie kann man den maximalen Arbeitsspeicher seines Autoit-Skripts begrenzen?
Hab im .com Forum den Hinweis auf das hier bekommen: http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx der Wert .PrivateBytes soll der gesuchte Wert für Win 7 sein, wie kann ich diesen für einen spezifischen Prozess abfragen kann?
Hi,
noch ein Ansatz:
http://www.autoitscript.com/forum/index.php?showtopic=110628&st=0&gopid=777355&
Kontrollier gffs die Ansicht Deines Taskmanagers. Die ausgegeben Bytes entsprechen Arbeitsspeicher - Privater Arbeitssatz
;-))
Stefan
Habs auch grade gesehen, ist ja mein Thread dort hehe ;).
Und ja der letzte Post dort ist die Lösung: http://www.autoitscript.com/forum/index.php?showtopic=110628&st=0&p=777355&#entry777355
Hier der verbesserte Code bzgl.>= Win7:
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
Global $PID
Global Const $Process_All_Access = 0x1F0FFF
$PID = ProcessExists(@AutoItPID)
If $PID = 0 Then
ConsoleWrite(@CRLF & "ERROR! Process " & $PID & " not found! Aborting..." & @CRLF)
Exit
EndIf
$ProcHandle = DllCall("kernel32.dll", "hwnd", "OpenProcess", "dword", $Process_All_Access, "int", False, "dword", $PID)
$ProcHandle = $ProcHandle[0]
MsgBox(0, "PrivateUsage Size", Round(_ProcessGetMem($ProcHandle) / 1024, 0) & " kb")
[/autoit] [autoit][/autoit] [autoit]DllCall("psapi.dll", "int", "CloseHandle", "hwnd", $ProcHandle)
DllCall("kernel32.dll", "int", "CloseHandle", "int", $ProcHandle)
Exit
Func _ProcessGetMem($ProcessHandle) ;get physical memory of the process -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
Local $structPROCESS_MEMORY_COUNTERS, $structPROCESS_MEMORY_COUNTERS_EX, $nSize, $aRet
If @OSBuild < 7600 Then
$structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; ulong_ptr WorkingSetSize; " & _
"dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _
"dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage") ;http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
$nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
$aRet = DllCall("psapi.dll", "int", "GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize) ;call GetProcessMemoryInfo
If $aRet[0] = 0 Then
ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF)
SetError(1, 0, $aRet[0])
EndIf
Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "WorkingSetSize")
Else
$structPROCESS_MEMORY_COUNTERS_EX = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; dword_ptr WorkingSetSize; " & _
"dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _
"dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage; " & _
"ulong_ptr PrivateUsage") ;http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
$nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS_EX)
$aRet = DllCall("Kernel32.dll", "int", "K32GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS_EX), "dword", $nSize) ;call GetProcessMemoryInfo
If $aRet[0] = 0 Then
ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF)
SetError(1, 0, $aRet[0])
EndIf
ConsoleWrite("WorkingSetSize: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "WorkingSetSize"), 0) & @CRLF & _
"PageFaultCount: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PageFaultCount"), 0) & @CRLF & _
"PeakWorkingSetSize: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PeakWorkingSetSize"), 0) & @CRLF & _
"QuotaPeakPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPeakPagedPoolUsage"), 0) & @CRLF & _
"QuotaPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPagedPoolUsage"), 0) & @CRLF & _
"QuotaPeakNonPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPeakNonPagedPoolUsage"), 0) & @CRLF & _
"QuotaNonPagePoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaNonPagePoolUsage"), 0) & @CRLF & _
"PagefileUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PagefileUsage"), 0) & @CRLF & _
"PeakPagefileUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PeakPagefileUsage"), 0) & @CRLF & _
"PrivateUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage"), 0) & @CRLF & @CRLF)
Return DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage")
EndIf
EndFunc ;==>_ProcessGetMem
Nichts desto trotz liefert PrivateUsage nicht den Speicher zurück, der im Taskmanager (WS Private) erscheint!
Die Suche geht weiter nach einer nicht WMI Lösung...
Gruß,
UEZ
Also mit WMI bekomme ich bei mir (Win7, 64Bit) die gleichen Werte, wie im Taskmanager:
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
$hGui = GUICreate('Process-Memory', 640, 480)
$hListview = GUICtrlCreateListView('Process|PID|Mem (privat)|Mem (peak)', 5, 5, 630, 440)
GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 1, 80)
GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 2, 120)
GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 3, 120)
$hWndListview = GUICtrlGetHandle($hListview)
$hRefresh = GUICtrlCreateButton('Refresh', 280, 450, 80, 25)
_RefreshListview()
GUISetState()
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hRefresh
_RefreshListview()
EndSwitch
WEnd
Func _RefreshListview()
Local $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $colItems, $strComputer
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = 'localhost'
Local $objWMIService, $colItems, $sItem
_GUICtrlListView_DeleteAllItems($hWndListview)
$objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\')
$colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_PerfRawData_PerfProc_Process', 'WQL', $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$sItem = ''
$sItem &= $objItem.Name & '|' & $objItem.CreatingProcessID & '|'
$sItem &= _ByteAutoSize($objItem.WorkingSetPrivate, 0, 2) & '|' & _ByteAutoSize($objItem.WorkingSetPeak, 0, 2)
GUICtrlCreateListViewItem($sItem, $hListview)
Next
EndFunc ;==>_RefreshListview
;===============================================================================
; Function Name: _ByteAutoSize($iSize[, $iRound][, $iFormat][, $bThousands])
; Description:: Gibt einen Bytewert in einer bestimmten Einheit zurück
; Parameter(s): $iSize = Größe in Byte übergeben
; $iRound = Anzahl der Nachkommastellen (0...8)
; $iFormat = bestimmt den Rückgabewert
; 0 = Automatisch (je nach übergebenen Wert)
; 1 = in Byte
; 2 = in KByte
; 3 = in MByte
; 4 = in GByte
; $bThousands = Rückgabe mit Tausendertrennzeichen (True/False)
; Requirement(s): #include <String.au3>
; Author(s): Oscar (http://www.autoit.de)
;===============================================================================
Func _ByteAutoSize($iSize, $iRound = 2, $iFormat = 0, $bThousands = True)
Local $aSize[4] = [' Byte', ' KByte', ' MByte', ' GByte'], $sReturn
If $iFormat < 0 Or $iFormat > 4 Then $iFormat = 0
If $iRound < 0 Or $iRound > 8 Then $iRound = 2
If Not IsBool($bThousands) Then $bThousands = False
$iSize = Abs($iSize)
If $iFormat = 0 Then
For $i = 30 To 0 Step -10
If $iSize > (2 ^ $i) Then
$iFormat = $i / 10 + 1
ExitLoop
EndIf
Next
EndIf
If $iFormat = 0 Then $iFormat = 1
$sReturn = StringFormat('%.' & $iRound & 'f', Round($iSize / (2 ^ (($iFormat - 1) * 10)), $iRound))
If $bThousands Then $sReturn = _StringAddThousandsSep($sReturn, '.', ',')
Return $sReturn & $aSize[$iFormat - 1]
EndFunc ;==>_ByteAutoSize
; #FUNCTION# ====================================================================================================================
; Name...........: _StringAddThousandsSep
; Description ...: Returns the original numbered string with the Thousands delimiter inserted.
; Syntax.........: _StringAddThousandsSep($sString[, $sThousands = -1[, $sDecimal = -1]])
; Parameters ....: $sString - The string to be converted.
; $sThousands - Optional: The Thousands delimiter
; $sDecimal - Optional: The decimal delimiter
; Return values .: Success - The string with Thousands delimiter added.
; Author ........: SmOke_N (orignal _StringAddComma
; Modified.......: Valik (complete re-write, new function name)
; ===============================================================================================================================
Func _StringAddThousandsSep($sString, $sThousands = -1, $sDecimal = -1)
Local $sResult = "" ; Force string
Local $rKey = "HKCU\Control Panel\International"
If $sDecimal = -1 Then $sDecimal = RegRead($rKey, "sDecimal")
If $sThousands = -1 Then $sThousands = RegRead($rKey, "sThousand")
Local $aNumber = StringRegExp($sString, "(\D?\d+)\D?(\d*)", 1) ; This one works for negatives.
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber[0]
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, StringLen($sThousands)) ; Strip leading thousands separator
If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep
Oscar schau mal zwei Posts höher den Link an ;). UEZ will das ja mit DLL machen ohne WMI.