- NSIS Discussion
- Execute Function Until a window comes pop up
Archive: Execute Function Until a window comes pop up
mazdakam
18th November 2007 00:41 UTC
Execute Function Until a window comes pop up
Hi
I am working to close WFP (Windows File Protection) window
and find a solution in this forum to close WFP i need to call a function -closeWFP that can close WFP.
so what is my problem:
as you know WFP appears when you are trying to delete/modify protected files
so in my installation i need to delete a dll and after that it takes 5-10 seconds to WFP appears and if i call function before it pop nothing happend
for this issue i use sleep 10000 (ms) command bedfore calling -closeWFP
but i want to know
1) is there any way for me to detect WFP window and then call -closeWFP?
or
2) Is trhere any way to still running closeWFP function untill WFP window pop?
3) do you have any other suggestion for me?
i need your help urgently
Thanks in advanced
mazdakam
18th November 2007 07:37 UTC
ding!
Afrow UK
18th November 2007 15:02 UTC
Try FindWindow. To get the window class (if it has one) you'd need to use Spy++ or a similar tool.
Stu
mazdakam
18th November 2007 17:35 UTC
hi
Afrow UK
listen i can detect the windows and can close them too by calling a function so it is not my problem
as i told before it takes 5-10 seconds to apear windows
so i need wait for it and then call my function to close it
i asked a way to detect window immediately and close it
or
any way to still running closeWFP function untill WFP window pop
....
Afrow UK
18th November 2007 22:44 UTC
If you can detect the window then what is the problem? Just loop until you get a valid window handle (but ensure you don't loop infinitely as well).
Stu
mazdakam
19th November 2007 06:35 UTC
thanks for answering...
i don't know how can i loop until i am newbie :)
this is a part of code that i told:
closeWFP
Sleep 10000
;Find and close first dialog
FindWindow$0 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'
;Find and close second dialog
FindWindow$1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
>FunctionEnd
>
Section -kbdfadll
SetOutPath "$SYSDIR"
SetOverwrite on
File "kbdfa.dll"
;!insertmacro InstallLib REGDLL NOTSHARED NOREBOOT_NOTPROTECTED kbdfa.dll $SYSDIRkbdfa.dll $SYSDIR
SectionEnd
>
after this the window apear after 5 - 10 seconds
and i close it y calling closeWFP function
Section -WFP2
>;nsExec::Exec '"$INSTDIR\CWFP.exe"'
>call closeWFP
SectionEnd
>
so tell me how can put it too a loop thanks
Afrow UK
19th November 2007 15:12 UTC
Use IsWindow on $0. Again put in a Sleep 500 and a counter so you don't loop forever.
Stu
mazdakam
19th November 2007 21:17 UTC
thanks i did it and it worked good
one anothr qudtion:
how can i repeat loop for x time
i mean like this:
for i=0 to 50
do it
i want this because in some case WFP windows will not pop and if i run this loop it wont break so i need repaet loop for 10 times only for example and if no window pop go to the end of function
this is my idea
but have you any other idea for my issue?
Afrow UK
19th November 2007 21:30 UTC
With LogicLib, ${For} $R0 1 1000 ... ${Next}
Stu
mazdakam
19th November 2007 23:03 UTC
i write it with Do while but it didn't work what is wrong with it:
closeWFP
>${Do}
;
Find and close first dialog
FindWindow$0 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'
>;Find and close second dialog
FindWindow$1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
Sleep 500
>***91;B***93; ${LoopUntil} $0 == '1'***91;/B***93;
>FunctionEnd
>
how can i tell LoopUntil window is not pop?
Afrow UK
20th November 2007 08:46 UTC
You cannot do it safely without a counter. Use a For loop.
Stu
mazdakam
20th November 2007 12:36 UTC
i try to use for and while but i couldn't would you plz help more or write this loop for me?
mazdakam
20th November 2007 13:05 UTC
Offf I get tired of recoding to find solution
please some one take a look of this and tell me why it dowse not work correct
closeWFP
nok:
${If}$R1 <= 10
Iswindow$0 0 ok
FindWindow$0 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'
FindWindow $1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
MessageBox MB_OK "found a window"
goto Break
ok:
Sleep 1000
IntOp $R1 $R1+ 1
goto nok
>${Else}
>goto Break
${EndIf}
Break:
>FunctionEnd
>
or tell me how can i
break the loop after window find and closed
closeWFP
>${For} $R1 1 10
>;Find and close first dialog
FindWindow$0 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'
>;Find and close second dialog
FindWindow$1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
>Sleep 1000
>${Next}
>FunctionEnd
>
Afrow UK
20th November 2007 17:59 UTC
Function closeWFP
${For} $R0 1 25
FindWindow $R1 "" "Windows File Protection"
StrCmp $R1 0 0 Close
Sleep 1000
${Next}
Return
Close:
System::Call 'user32::PostMessageA(i,i,i,i) i($R1,${WM_COMMAND},2,0)'
FindWindow $R1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($R1,${WM_COMMAND},6,0)'
FunctionEnd
Stu
mazdakam
20th November 2007 18:15 UTC
Yes! it works :)
this is because i did not know StrCmp
Thank you so much for your time
Afrow UK
20th November 2007 18:17 UTC
I used StrCmp instead of IsWindow because FindWindow returns 0 if no windows are found. It could have been IsWindow $R1 Close as well.
Stu
mazdakam
20th November 2007 18:37 UTC
i make a win Macro for an alternative to close WFP maybe it helps someone :)
you can download it in attachment
mazdakam
21st November 2007 04:25 UTC
i write it with Iswindow and it works too as you told :)
closeWFP
>${For} $R0 1 100
FindWindow $R1 "" "Windows File Protection"
Iswindow $R1 Close 0
Sleep 100
>${Next}
Return
>Close:
System::Call 'user32::PostMessageA(i,i,i,i) i($R1,${WM_COMMAND},2,0)'
FindWindow $R1 "" "Windows File Protection"
System::Call 'user32::PostMessageA(i,i,i,i) i($R1,${WM_COMMAND},6,0)'
>FunctionEnd
>