Sign in to follow this  
Followers 0
maqleod

winpstools front-end

2 posts in this topic

I decided to do this as a practice in writing front-ends for existing open source command line utilities. This one had very basic features (although I still have yet to implement everything) so I thought it would be a good start. I'm posting it as an example for anyone who might find it useful for doing the same sort of thing. You'll need to actually go and download WinPsTools to use this script, you can get it at: http://sourceforge.net/projects/winpstools/

#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Process.au3>
#include <A3LListView.au3>
#NoTrayIcon

$name = "WinPsTools GUI"

$parent = GUICreate($name,350,580)
Opt("RunErrorsFatal", 0)
$contextmenu = GUICtrlCreateContextMenu ()
$fileopt = GUICtrlCreateMenu ("&File")
$ontopitem = GUICtrlCreateMenuitem ("Always On Top",$fileopt)
$top = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\WinPsTools", "AlwaysOnTop")
if $top = 0 then
GUICtrlSetState(-1,$GUI_UNCHECKED)
WinSetOnTop($name, "", 0)
elseif $top = 1 then
GUICtrlSetState(-1,$GUI_CHECKED)
WinSetOnTop($name, "", 1)
endif
$exititem = GUICtrlCreateMenuitem("Exit",$fileopt)
$helpopt = GUICtrlCreateMenu("About")
$aboutitem = GUICtrlCreateMenuitem("About",$helpopt)

$listview = GUICtrlCreateListView("Process|PID|Parent PID|Priority",20,30,315,460,BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP))
$wpinfo = Run("wps.exe",@ScriptDir,@SW_HIDE,$STDOUT_CHILD)
$line = StdoutRead($wpinfo)
$info = StringSplit($line,@CR)
For $n = 2 to $info[0]
$brokeninfo = StringSplit($info[$n],Chr("9"))
GUICtrlCreateListviewItem($brokeninfo[5] & "|" & $brokeninfo[2] & "|" & $brokeninfo[3] & "|" & $brokeninfo[4],$listview)
GUICtrlSetImage(-1, "shell32.dll", 25)
GuiCtrlSetImage(-1,_GetProcessPath($brokeninfo[2]),0)
Next

$kill = GUICtrlCreateButton("Kill Process",120,510,75,25)
$refresh = GUICtrlCreateButton("Refresh",40,510,75,25)
$close = GUICtrlCreateButton("Close",200,510,75,25)


GUISetState(@SW_SHOW,$parent)

_GUICtrlListViewSetColumnWidth($listview, 0, $LVSCW_AUTOSIZE)
_GUICtrlListViewSetColumnWidth($listview, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListViewSetColumnWidth($listview, 2, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListViewSetColumnWidth($listview, 3, $LVSCW_AUTOSIZE_USEHEADER)

Do
$msg = GUIGetMsg()

Select
Case $msg = $kill
$split = StringSplit(GUICtrlRead(GUICtrlRead($listview)),"|")
Run(@ComSpec & " /c " & "wkill.exe " & $split[2],@ScriptDir, @SW_HIDE)
GuiCtrlDelete(GUICtrlRead($listview))
Case $msg = $refresh
RefreshProcess()
EndSelect

if $msg = $ontopitem then
if BitAnd(GUICtrlRead($ontopitem),$GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($ontopitem,$GUI_UNCHECKED)
RegWrite("HKEY_CURRENT_USER\SOFTWARE\WinPsTools","AlwaysOnTop","REG_SZ","0")
WinSetOnTop("", "", 0)
else
GUICtrlSetState($ontopitem,$GUI_CHECKED)
RegWrite("HKEY_CURRENT_USER\SOFTWARE\WinPsTools","AlwaysOnTop","REG_SZ","1")
WinSetOnTop("", "", 1)
endif
endif

if $msg = $aboutitem then
$child1 = GUICreate("About",220, 220,-1,-1,-1,$WS_EX_ACCEPTFILES,$parent)
$font = "Ariel"
Opt("RunErrorsFatal", 0)
GUICtrlCreateLabel ($name,50,30,150,30)
GUICtrlSetFont (-1,10,400, $font)
GUICtrlCreateIcon("youricon.ico",-1,85,60,48,48)
GUICtrlCreateLabel ("Written by MaQleod",55,120,150,30)
GUICtrlSetFont (-1,10,400, $font)
$aboutok = GUICtrlCreateButton ("OK",75,170,75,25)
GUISetState()
Do
$msg1 = GUIGetMsg()
if $msg1 = $aboutok then
ExitLoop
endif
Until $msg1 = $GUI_EVENT_CLOSE
GUIDelete($child1)
endif

if $msg = $close or $msg = $exititem then
ExitLoop
endif

Until $msg = $GUI_EVENT_CLOSE
GUIDelete()

Func RefreshProcess()
_GUICtrlListViewDeleteAllItems($listview)
$wpinfo = Run("wps.exe",@ScriptDir,@SW_HIDE,$STDOUT_CHILD)
$line = StdoutRead($wpinfo)
$info = StringSplit($line,@CR)
For $n = 2 to $info[0]
$brokeninfo = StringSplit($info[$n],Chr("9"))
GUICtrlCreateListviewItem($brokeninfo[5] & "|" & $brokeninfo[2] & "|" & $brokeninfo[3] & "|" & $brokeninfo[4],$listview)
GUICtrlSetImage(-1, "shell32.dll", 25)
GuiCtrlSetImage(-1,_GetProcessPath($brokeninfo[2]),0)
Next
EndFunc

Func _GetProcessPath($PID2) ;thanks to alzoprocessmanager
Local $Process, $Modules, $Ret
;Const $PROCESS_QUERY_INFORMATION = 0x0400
;Const $PROCESS_VM_READ = 0x0010
$Process = DllCall("kernel32.dll", "hwnd", "OpenProcess", "int", _
BitOR($PROCESS_QUERY_INFORMATION, $PROCESS_VM_READ), "int", 0, "int", $PID2)
If $Process[0] = 0 Then Return SetError(1)
$Modules = DllStructCreate("int[1024]")
DllCall("psapi.dll", "int", "EnumProcessModules", "hwnd", $Process[0], "ptr", DllStructGetPtr($Modules), _
"int", DllStructGetSize($Modules), "int_ptr", 0)
$Ret = DllCall("psapi.dll", "int", "GetModuleFileNameEx", "hwnd", $Process[0], "int", DllStructGetData($Modules, 1), _
"str", "", "int", 2048)
$Modules = 0
If StringLen($Ret[3]) = 0 Then Return SetError(1)
Return $Ret[3]
EndFunc   ;==>_GetProcessPath

[u]You can download my projects at:[/u] Pulsar Software

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  
Followers 0