Guest hannes08 Posted November 6, 2007 Share Posted November 6, 2007 Hi! I am just writing a small script for Terminal Server useres that will enable them to kill their running Word / Excel / Powerpoint applications. To find out what programs/processes a user is running I go through the window list (WinList()) and check for every window if it is visible for the user and it contains special words that identify the application. With the Windows Title I can find out the process. Take a look at the code: CODE#include <Array.au3> #include <GuiConstants.au3> ;Variablen definieren $var = WinList() Dim $a_doc_l[1] Dim $a_xls_l[1] Dim $a_ppt_l[1] If @OSLang = "0407" OR @OSLang = "0807" OR @OSLang = "0c07" OR @OSLang = "1007" OR @OSLang = "1407" Then $tx_title = "Kill Office Tool" $tx_desc1 = "Please choose the application you want to close" $tx_choose_doc = "Microsoft Word" $tx_choose_xls = "Microsoft Excel" $tx_choose_ppt = "microsoft PowerPoint" $tx_button1 = "Kill selected application" $tx_button1 = "Exit this tool" $msgb_1_title = $tx_title $msgb_1_tx = "There are no Microso0ft Office applications running" & @CRLF & "Nothing to terminate." Else $tx_title = "Kill Office Tool" $tx_desc1 = "Please choose the application you want to close" $tx_choose_doc = "Microsoft Word" $tx_choose_xls = "Microsoft Excel" $tx_choose_ppt = "microsoft PowerPoint" $tx_button1 = "Kill selected application" $tx_button2 = "Exit this tool" $msgb_1_title = $tx_title $msgb_1_tx = "There are no Microso0ft Office applications running" & @CRLF & "Nothing to terminate." EndIf ;List all Windows For $i = 1 To $var[0][0] If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then If StringInStr($var[$i][0], "Microsoft Word") > 0 Then $pid = WinGetProcess($var[$i][0]) _ArrayAdd($a_doc_l, $pid) $a_doc_l[0] = $a_doc_l[0] + 1 ElseIf StringInStr($var[$i][0], "Microsoft Excel") > 0 Then $pid = WinGetProcess($var[$i][0]) _ArrayAdd($a_xls_l, $pid) $a_xls_l[0] = $a_xls_l[0] + 1 ElseIf StringInStr($var[$i][0], "Microsoft PowerPoint") > 0 Then $pid = WinGetProcess($var[$i][0]) _ArrayAdd($a_ppt_l, $pid) $a_ppt_l[0] = $a_ppt_l[0] + 1 EndIf EndIf Next If $a_doc_l[0] + $a_xls_l[0] + $a_ppt_l[0] > 0 Then GUICreate($tx_title, 180, 230, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Label_1 = GUICtrlCreateLabel($tx_desc1, 10, 10, 160, 30) $p = 0 If $a_doc_l > 0 Then $Radio_1 = GUICtrlCreateRadio($tx_choose_doc, 40, 50, 120, 20) Else $Radio_1 = "" EndIf If $a_xls_l > 0 Then $Radio_2 = GUICtrlCreateRadio($tx_choose_xls, 40, 80, 120, 20) Else $Radio_2 = "" EndIf If $a_ppt_l > 0 Then $Radio_3 = GUICtrlCreateRadio($tx_choose_ppt, 40, 110, 120, 20) Else $Radio_3 = "" EndIf $Beenden = GUICtrlCreateButton($tx_button1, 15, 145, 150, 30) $Ende = GUICtrlCreateButton($tx_button2, 40, 195, 100, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Ende ExitLoop Case $msg = $Beenden If BitAND(GUICtrlRead($Radio_1), $GUI_CHECKED) = $GUI_CHECKED Then For $k = 1 To $k <= $a_doc_l[0] ProcessClose($a_doc_l[$k]) Next ExitLoop EndIf If BitAND(GUICtrlRead($Radio_2), $GUI_CHECKED) = $GUI_CHECKED Then For $k = 1 To $k <= $a_xls_l[0] ProcessClose($a_xls_l[$k]) Next ExitLoop EndIf If BitAND(GUICtrlRead($Radio_3), $GUI_CHECKED) = $GUI_CHECKED Then For $k = 1 To $k <= $a_ppt_l[0] ProcessClose($a_ppt_l[$k]) Next EndIf ExitLoop Case Else ;;; EndSelect WEnd Else MsgBox(64, $msgb_1_title, $msgb_1_tx) EndIf Exit Func IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Now I got an additional request that processes should be killed that are NOT visible for the user. Is there any possibility to check for the owner of a process? Best regards, Hannes Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 6, 2007 Share Posted November 6, 2007 Is there any possibility to check for the owner of a process? If you use my _ProcessListProperties() function, it will come out at [n][3] in the returned array. If that's too much overkill (the _ProcessListProperties() function is intended to return a lot more than just the owner) you could pare it down to just that one property by looking at the code. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now