Innovative Posted December 5, 2007 Posted December 5, 2007 How can i make when there is a new process, the script will perform a action.. please help =(
weaponx Posted December 5, 2007 Posted December 5, 2007 Too easy:#414931Just modify it so instead of killing the new process, it will just trigger a function.
Innovative Posted December 5, 2007 Author Posted December 5, 2007 How do i edit to make it to detect a new process then perform an action ? thx for your help anyway =)
weaponx Posted December 5, 2007 Posted December 5, 2007 That example wasn't simple enough? ;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then MsgBox(0,"","New process found: " & $ListTwo[$X][0]) someFunction() EndIf Next ;Check every 3 seconds Sleep (3000) WEnd Func someFunction() MsgBox(0,"","A new process was opened") EndFunc
Innovative Posted December 5, 2007 Author Posted December 5, 2007 Now i need another help, how can i get the program title by the process name .. because WinGetTitle only works by entering the window title not process name.. I tried to enter WinGetTitle($ListTwo[$X][1], "") but failed =(
weaponx Posted December 5, 2007 Posted December 5, 2007 Now i need another help, how can i get the program title by the process name .. because WinGetTitle only works by entering the window title not process name.. I tried to enter WinGetTitle($ListTwo[$X][1], "") but failed =( That part isn't so simple. One process can have multiple windows. This is a bit trickier: http://www.autoitscript.com/forum/index.ph...mp;#entry287214
Innovative Posted December 6, 2007 Author Posted December 6, 2007 I dont understand , with that function it can return the new process's PID but which function must i use ? WinGetTitle or _ProcessGetName to get the FULL PROGRAM TITLE (like "Paint" not "paint.exe")
Innovative Posted December 6, 2007 Author Posted December 6, 2007 EDIT : I tried this but failed it gave me an error (Badly formatted func) Func ProcessGetWindow($ListTwo[$X][1]) If IsNumber($ListTwo[$X][1]) = 0 Or ProcessExists(ProcessGetName($ListTwo[$X][1])) = 0 Then SetError(1) Else Local $WinList = WinList() Local $i = 1 Local $WindowTitle = "" While $i <= $WinList[0][0] And $WindowTitle = "" If WinGetProcess($WinList[$i][0], "") = $ListTwo[$X][1] Then $WindowTitle = $WinList[$i][0] Else $i = $i + 1 EndIf WEnd Return $WindowTitle EndIf EndFunc
weaponx Posted December 6, 2007 Posted December 6, 2007 You can thank Sm0ke_N for the function I found here:http://www.autoitscript.com/forum/index.ph...st&p=313837The function I posted earlier (ProcessGetHwnd) didn't work for me.expandcollapse popup;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then MsgBox(0,"","New process found: " & $ListTwo[$X][0] & @CRLF & "Window title: " & _WinGetByPID($ListTwo[$X][1])) ;someFunction() EndIf Next ;Check every 3 seconds Sleep (3000) WEnd Func someFunction() MsgBox(0,"","A new process was opened") EndFunc Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds If IsString($iPID) Then $iPID = ProcessExists($iPID) Local $aWList = WinList(), $sHold For $iCC = 1 To $aWList[0][0] If WinGetProcess($aWList[$iCC][1]) = $iPID And _ BitAND(WinGetState($aWList[$iCC][1]), 2) Then If $nArray Then Return $aWList[$iCC][0] $sHold &= $aWList[$iCC][0] & Chr(1) EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, 0) EndFunc
Innovative Posted December 6, 2007 Author Posted December 6, 2007 (edited) Now heres the part of my script that have problems.. Problem 1 :It will only disable the window if i get out of that new process.. it wont disable the window if i do not go out of the window.. How can i make it disable even if im active in that window Problem 2 : the msgbox keep looping after 3 seconds -.- Problem 3 : The new gui dont show up when a new process is detected.. Please help =) thx .. P.s. : weaponx , i have added nice comments to your profile =) thanks for your help! $getnewprocessname = _ProcessGetName ( $ListTwo[$X][1] ) $PId = ProcessGetId($getnewprocessname); Gets the PId WinSetState( ProcessGetWindow($PId[1]), "", @SW_Disable) Guicreate( "New process detected!", 400, 250) GuiCtrlcreatelabel("bla",150,150) EndIf Next ;Check every 3 seconds Sleep (3000) Edited December 6, 2007 by CrazeStar1074
Innovative Posted December 6, 2007 Author Posted December 6, 2007 Problem 3 is solved =) please help me on problem 1 and 2, thanks =)
weaponx Posted December 7, 2007 Posted December 7, 2007 The only one of your problems I understand is 2. You can wrap the code in another while loop and use ExitLoop after a new process is found. expandcollapse popupWhile 1 ;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then MsgBox(0,"","New process found: " & $ListTwo[$X][0] & @CRLF & "Window title: " & _WinGetByPID($ListTwo[$X][1])) ;someFunction() ExitLoop 2 EndIf Next ;Check every 3 seconds Sleep (3000) WEnd WEnd Func someFunction() MsgBox(0,"","A new process was opened") EndFunc Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds If IsString($iPID) Then $iPID = ProcessExists($iPID) Local $aWList = WinList(), $sHold For $iCC = 1 To $aWList[0][0] If WinGetProcess($aWList[$iCC][1]) = $iPID And _ BitAND(WinGetState($aWList[$iCC][1]), 2) Then If $nArray Then Return $aWList[$iCC][0] $sHold &= $aWList[$iCC][0] & Chr(1) EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, 0) EndFunc
nfwu Posted December 7, 2007 Posted December 7, 2007 (edited) What I think @op wants is to disable any new windows that show up. $ListOne = WinList () While 1 $ListTwo = WinList () For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by HWND For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then MsgBox(0,"","New window found: " & $ListTwo[$X][0] & @CRLF & $ListTwo[$X][1]) WinSetState( $ListTwo[$X][0], "", @SW_Disable) ExitLoop 2 EndIf Next $ListOne = $ListTwo WEnd (I haven't used AutoIt for 6 months so am rusty.) #) Edited December 7, 2007 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
Innovative Posted December 7, 2007 Author Posted December 7, 2007 Now , another problem -.- sorry for the trouble This is part of the script which is the problem part. I press accept and nothing happens same as deny , i press deny , nothing happened also $accept = GUICtrlcreatebutton("Accept", 70, 310, 80, 30) $deny = GUICtrlcreatebutton("Deny", 200, 310, 80, 30) If _IsPressed($accept) Then GUISetState(@SW_HIDE, $processgui) Endif If _IsPressed($deny) Then ProcessClose($getprocessname) Endif
weaponx Posted December 7, 2007 Posted December 7, 2007 (edited) Hey look everyone its Windows Vista! _IsPressed isn't for GUI controls at all. You can put Event handlers on your buttons. Opt("GUIOnEventMode", 1) $accept = GUICtrlcreatebutton("Accept", 70, 310, 80, 30) GUICtrlSetOnEvent(-1, "AcceptPressed") $deny = GUICtrlcreatebutton("Deny", 200, 310, 80, 30) GUICtrlSetOnEvent(-1, "DenyPressed") Func AcceptPressed() GUISetState(@SW_HIDE, $processgui) EndFunc Func DenyPressed() ProcessClose($getprocessname) EndFuncoÝ÷ ÚÔ±æ º)²Æ zZ(¥«¢+ØÀÌØíÁÐôU% ÑɱÉÑÕÑѽ¸ ÅÕ½ÐíÁÐÅÕ½Ðì°ÜÀ°ÌÄÀ°àÀ°ÌÀ¤(ÀÌØí¹äôU% ÑɱÉÑÕÑѽ¸ ÅÕ½Ðí¹äÅÕ½Ðì°ÈÀÀ°ÌÄÀ°àÀ°ÌÀ¤()]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤()MÝ¥Ñ ÀÌØíµÍ( ÍÀÌØíÁÐ(U%MÑMÑÑ¡M]}!%°ÀÌØíÁɽÍÍÕ¤¤( ÍÀÌØí¹ä(AɽÍÍ ±½Í ÀÌØíÑÁɽÍ͹µ¤)¹MÝ¥Ñ )]¹ You really need to review the examples in the Help File. Especially the Gui Reference. Edited December 7, 2007 by weaponx
Innovative Posted December 7, 2007 Author Posted December 7, 2007 I really have lots of problems -.- this is another problem Once i click accept it said "Error: Array variable has incorrect number of subscripts or subscript dimension rage exceeded." Opt("GUIOnEventMode", 1) $accept = GUICtrlcreatebutton("Accept", 70, 310, 80, 30) GUICtrlSetOnEvent(-1, "AcceptPressed") $deny = GUICtrlcreatebutton("Deny", 200, 310, 80, 30) GUICtrlSetOnEvent(-1, "DenyPressed") Func AcceptPressed() WinSetState(_WinGetByPID($ListTwo[$X][1]), "", @SW_disable) GUISetState(@SW_HIDE, $processgui) EndFunc Func DenyPressed() ProcessClose($getprocessname) GUISetState(@SW_HIDE, $processgui) EndFunc
Innovative Posted December 8, 2007 Author Posted December 8, 2007 weaponx please help me, i need to compelete this job by tommorow
weaponx Posted December 8, 2007 Posted December 8, 2007 You keep posting pieces of a script and i'm never sure if that piece is even faulty...anyways you are getting that error because you are using $ListTwo outside the scope it was created in. You need to pass it as a paramater or add Global to the beginning of your array declarations: Global $ListOne = WinList () and Global $ListTwo = WinList ()
Innovative Posted December 8, 2007 Author Posted December 8, 2007 Heres the whole script, i've already changed it to global but it still displayed the error expandcollapse popup#include <process.au3> #include <misc.au3> While 1 Global $ListOne = ProcessList () ;Store current processlist "state" While 1 Global $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then $getpids = ProcessExists ( $listtwo[$X][1] ) $getprocessname = _ProcessGetName ( $ListTwo[$X][1] ) WinSetState(_WinGetByPID($ListTwo[$X][1]), "", @SW_Disable) $processgui = GUICreate("New process found!", 350, 350) Guictrlcreatelabel(" To protect your computer from unknown process,"& @CRLF &" ProcessDefender has disabled a process "& @CRLF &""& @CRLF &"The following program wants to start on your computer. If this is "& @CRLF &"expected you should permit it to do so. If you are unsure about this "& @CRLF &" program then deny it from executing.", 15, 20 ) GUISetState(@SW_SHOW, $processgui) $listviewmain = GUICtrlCreateListView ( "ProgramName|ProcessName|ProcessID (PID)", 45, 100 , 260 , 200 ) GUICtrlCreateListViewItem (""& _WinGetByPID($ListTwo[$X][1]) &"|"& $getprocessname &"|"& $getpids &"", $listviewmain) Opt("GUIOnEventMode", 1) $accept = GUICtrlcreatebutton("Accept", 70, 310, 80, 30) GUICtrlSetOnEvent(-1, "AcceptPressed") $deny = GUICtrlcreatebutton("Deny", 200, 310, 80, 30) GUICtrlSetOnEvent(-1, "DenyPressed") Func AcceptPressed() WinSetState(_WinGetByPID($ListTwo[$X][1]), "", @SW_disable) GUISetState(@SW_HIDE, $processgui) EndFunc Func DenyPressed() ProcessClose($getprocessname) GUISetState(@SW_HIDE, $processgui) EndFunc ExitLoop 2 EndIf Next ;Check every 3 seconds Sleep (3000) WEnd WEnd Func someFunction() MsgBox(0,"","A new process was opened") EndFunc Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds If IsString($iPID) Then $iPID = ProcessExists($iPID) Local $aWList = WinList(), $sHold For $iCC = 1 To $aWList[0][0] If WinGetProcess($aWList[$iCC][1]) = $iPID And _ BitAND(WinGetState($aWList[$iCC][1]), 2) Then If $nArray Then Return $aWList[$iCC][0] $sHold &= $aWList[$iCC][0] & Chr(1) EndIf Next If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(1, 0, 0) EndFunc
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