Jump to content

Recommended Posts

Posted

Hi,

I'm playing with this code and realized that the GUICtrlCreateListViewItem return 0.

Am i doing something wrong here?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Global $Processes[1], $Processes_Run = False
$MGui = GUICreate("Simple Task Manager", 615, 438, 192, 124)
$MLV = GUICtrlCreateListView("Process Id|#No|Virtual Size|Description|Command Line|Executable Path", 0, 42, 615, 396)
_ListProcess()
GUISetState(@SW_SHOW)
_ArrayDisplay($Processes)

Func _ListProcess()
Local $i = 0
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $Wbem = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $Process = $Wbem.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $Proc In $Process
$i += 1
If $Processes_Run Then
If $i > $Processes[0]-1 Then
ReDim $Processes[$i+1]
$Processes[$i] = GUICtrlCreateListViewItem($Proc.Caption &'|'& $i & '|'& $Proc.ProcessId &'|'& $Proc.VirtualSize &'|'& $Proc.HandleCount &'|'& $Proc.CommandLine &'|'& $Proc.ExecutablePath, $MLV)
Else
GUICtrlSetData($Processes[$i], $Proc.Caption &'|'& $i &'|'& $Proc.ProcessId &'|'& $Proc.VirtualSize &'|'& $Proc.HandleCount &'|'& $Proc.CommandLine &'|'& $Proc.ExecutablePath, $MLV)
EndIf
Else
ReDim $Processes[$i+1]
$Processes[$i] = GUICtrlCreateListViewItem($Proc.Caption &'|'& $i &'|'& $Proc.ProcessId &'|'& $Proc.VirtualSize &'|'& $Proc.HandleCount &'|'& $Proc.CommandLine &'|'& $Proc.ExecutablePath, $MLV)
EndIf
Next
If Not $Processes_Run Then $Processes_Run = True
$Wbem = 0
$Process = 0
EndFunc

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Posted (edited)

You would require #RequireAdmin

Test this

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Global $Processes[1], $Processes_Run = False
$MGui = GUICreate("Simple Task Manager", 615, 438, 192, 124)
$MLV = GUICtrlCreateListView("S.No|Process Id|#No|Virtual Size|Description|Command Line|Executable Path", 0, 42, 615, 396)
_ListProcess()
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($Processes)

Func _ListProcess()
Local $i = 0
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $Wbem = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $Process = $Wbem.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $Proc In $Process
ReDim $Processes[$i + 1]
$Processes[$i] = GUICtrlCreateListViewItem($i & "|" & $Proc.Caption & '|' & $i & '|' & $Proc.ProcessId & '|' & $Proc.VirtualSize & '|' & $Proc.HandleCount & '|' & $Proc.CommandLine & '|' & $Proc.ExecutablePath, $MLV)
If $Processes[$i] = 0 Then ConsoleWrite("0 at " & $i & @CR)
$i += 1
Next
If Not $Processes_Run Then $Processes_Run = True
$Wbem = 0
$Process = 0
EndFunc ;==>_ListProcess

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

I have tried the given code but seems like problem is still there.

Here from the console.

0 at 3
0 at 4
0 at 5
0 at 6
0 at 7
0 at 8
0 at 9
0 at 10
0 at 11
0 at 12
0 at 13
0 at 14
0 at 15
0 at 16
0 at 17
0 at 18
0 at 19
0 at 20
0 at 21
0 at 22
0 at 23
0 at 24
0 at 25
0 at 26
0 at 27
0 at 28
0 at 29
0 at 30
0 at 31
0 at 32
0 at 33
0 at 34
0 at 35
0 at 36
0 at 37
0 at 38
0 at 39
0 at 40
0 at 41
0 at 42
0 at 43
0 at 44
0 at 45
0 at 46
0 at 47
0 at 48
0 at 49
0 at 50
0 at 51
0 at 52
0 at 53
0 at 54
0 at 55
0 at 56
0 at 57
0 at 58
0 at 59
0 at 60
0 at 61
0 at 62
0 at 63
0 at 64
0 at 65
0 at 67
0 at 68
0 at 69
0 at 70
0 at 71
0 at 72
0 at 73
0 at 74
0 at 75
0 at 76
Posted

Are you using a 64-bit OS ?

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted (edited)

Im using Vista Business 32bit and AutoIt v3.3.8.81.

I also have tried on Windows 7 23Bit and get the same result.

Edited by biase
Posted (edited)

Sorry i did some tests and found that after receiving the Admin rights the ConsoleWrite didn't work on my computer..

I tried with msgbox and it still gives me 0

need to do some more test..!

Tests in vain

Maybe there were a lot of items, I removed the Executable path data and everything seems to be okay !!

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Global $Processes[1], $Processes_Run = False
$MGui = GUICreate("Simple Task Manager", 615, 438, 192, 124)
$MLV = GUICtrlCreateListView("S.No|Process Id|#No|Virtual Size|Description|Command Line|Executable Path", 0, 42, 615, 396)
_ListProcess()
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($Processes)

Func _ListProcess()
Local $i = 0
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $Wbem = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $Process = $Wbem.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $Proc In $Process
ReDim $Processes[$i + 1]
$Processes[$i] = GUICtrlCreateListViewItem($i & "|" & $Proc.Caption & '|' & $i & '|' & $Proc.ProcessId & '|' & $Proc.VirtualSize & '|' & $Proc.HandleCount & '|' & $Proc.CommandLine , $MLV)
ConsoleWrite($i & ":" & $Processes[$i] & @CR)
$i += 1
Next
If Not $Processes_Run Then $Processes_Run = True
$Wbem = 0
$Process = 0
EndFunc ;==>_ListProcess

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd

Maybe somewhat similar could be a workaround..

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Global $Processes[1], $Processes_Run = False
$MGui = GUICreate("Simple Task Manager", 615, 438, 192, 124)
Global $hLV = GUICtrlCreateListView("S.No|Process Id|#No|Virtual Size|Description|Command Line|Executable Path", 0, 42, 615, 396)
_ListProcess()
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($Processes)

Func _ListProcess()
Local $i = 0
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $Wbem = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $Process = $Wbem.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $Proc In $Process
_GUICtrlListView_AddItem($hLV, $i)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.Caption, 1)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.ProcessId, 2)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.VirtualSize, 3)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.HandleCount, 4)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.CommandLine, 5)
_GUICtrlListView_AddSubItem($hLV, $i, $Proc.Caption, 6)
$i += 1
Next
$Wbem = 0
$Process = 0
EndFunc ;==>_ListProcess

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd

Finally the error was one extra column was added.

This would solve the problem

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Global $Processes[1], $Processes_Run = False
$MGui = GUICreate("Simple Task Manager", 615, 438, 192, 124)
$MLV = GUICtrlCreateListView("S.No|Process Id|#No|Virtual Size|Description|Command Line|Executable Path", 0, 42, 615, 396)
_ListProcess()
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($Processes)

Func _ListProcess()
Local $i = 0
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $Wbem = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $Process = $Wbem.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $Proc In $Process
ReDim $Processes[$i + 1]
$Processes[$i] = GUICtrlCreateListViewItem( $i & _
"|" & $Proc.Caption & _
'|' & $Proc.ProcessId & _
'|' & $Proc.VirtualSize & _
'|' & $Proc.HandleCount & _
'|' & $Proc.CommandLine & _
'|' & $Proc.ExecutablePath, $MLV )
If $Processes[$i] = 0 Then ConsoleWrite("0 at " & $i & @CR)
$i += 1
Next
If Not $Processes_Run Then $Processes_Run = True
$Wbem = 0
$Process = 0
EndFunc ;==>_ListProcess

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted

Thanks for the answer.

Finally the error was one extra column was added.

How stupid of me didn't notice there was extra column.

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
×
×
  • Create New...