inferno123 Posted September 2, 2008 Posted September 2, 2008 (edited) Hi everyone I have written a piece of code that is capable of killing(closing) a window not by its name but by the module name that has inititiated a window. In the environment I work killing windows by name was too much trouble because we support 35 countries and New hardware wizard windows name is different in every language. I enclose the code that kills "New Hardware Wizard Windows" by module name. If it has already been done in any form I apologize in advance. Thanks expandcollapse popup; ==================================================================================================== ======================== ; Name...........: $Kill_hwd_wizard_windows ; Description ...: Script enumerates exisitng windows(both active and hidden) and compare smodule names.If there is match it sends ; ...............: WM_CLOSE message to the window control in order to close it. ; Author ........: Pawel Szuszkiewicz(Inferno123) ; Remarks .......: ; ==================================================================================================== =========================== #include<Security.au3> #include<StructureConstants.au3> #include<WinAPI.au3> #include<Constants.au3> #include <Array.au3> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Global Const $WM_CLOSE = 0x0010 Global Const $HWD_module_name = "C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\COMCTL32.dll" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $list_all_windows = WinList() Do WinList() Sleep(1000) Until $list_all_windows[0][0] <> 0 $handle = DLLCallbackRegister ("_EnumWindowsProc", "int", "hwnd;lparam") For $a = 1 To 20 Step + 1 Hardware_wizard_main() Next DllCallbackFree ($handle) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FUNCTIONS START;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func Hardware_wizard_main() $HWD_Main = DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr ($handle), "lparam", 10) If @error Then MsgBox(0, "", "@ERROR: " & @error & @CRLF & "@EXTENDED: " & @extended) Else Return False $WinAPI_Error = _WinAPI_GetLastError () If $WinAPI_Error <> 0 Then MsgBox(0, "EnumWindows", "Error " & _WinAPI_GetLastError () & @CRLF & _WinAPI_GetLastErrorMessage ()) Exit EndIf Return $HWD_Main [0] <> 0 EndIf EndFunc ;==>Hardawer_wizard_main Func _EnumWindowsProc($hwnd, $lParam) Local $FileName $ModuleFileName = GetWindowModuleFileName($hwnd, $FileName, 250) If WinGetTitle($hwnd) <> "" And BitAND(WinGetState($hwnd), 2) And $ModuleFileName <> "" Then If $ModuleFileName = $HWD_module_name Then SendMessage($hwnd, $WM_CLOSE, 0, 0) ;SendMessage($hWnd,0x0112,0xF060,0) Sleep(1000) EndIf EndIf Return $hwnd EndFunc ;==>_EnumWindowsProc Func SendMessage($hwnd, $Msg, $wParam, $lParam) $result = DllCall("user32.dll", "int", "SendMessage", "hwnd", $hwnd, "int", $Msg, "int", $wParam, "int", $lParam) If @error Then MsgBox(0, "", "@ERROR: " & @error & @CRLF & "@EXTENDED: " & @extended) Else $WinAPI_Error = _WinAPI_GetLastError () If $WinAPI_Error <> 0 Then MsgBox(0, "SendMessage", "Error " & _WinAPI_GetLastError () & @CRLF & _WinAPI_GetLastErrorMessage ()) Exit EndIf Return $result[0] EndIf EndFunc ;==>SendMessage Func GetWindowModuleFileName($hwnd, $FileName, $FileNameMax) $result = DllCall("user32.dll", "long", "GetWindowModuleFileName", "hwnd", $hwnd, "str", $FileName, "long", $FileNameMax) If @error Then MsgBox(0, "", "@ERROR: " & @error & @CRLF & "@EXTENDED: " & @extended) Else Return $result[2] EndIf EndFunc ;==>GetWindowModuleFileName ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FUNCTIONS END;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF SCRIPT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; I have tested only on Windows XP Edited September 2, 2008 by inferno123
MadBoy Posted September 2, 2008 Posted September 2, 2008 Impressive work ;-) Keep up the good work! My little company: Evotec (PL version: Evotec)
James Posted September 2, 2008 Posted September 2, 2008 Very clever! This should defintley be rated 5 stars! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
stamandster Posted September 9, 2008 Posted September 9, 2008 Nice script! How would I define other windows that I would want killed?
inferno123 Posted March 4, 2009 Author Posted March 4, 2009 You would need to provide a valid module name which initiated the window creation.
Skrip Posted March 4, 2009 Posted March 4, 2009 Can you explain how to get the module name? [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]
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