Skip to content
⌘ NSIS Forum Archive

Execute Function Until a window comes pop up

18 posts

mazdakam#

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
Afrow UK#
Try FindWindow. To get the window class (if it has one) you'd need to use Spy++ or a similar tool.

Stu
mazdakam#
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#
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#
thanks for answering...

i don't know how can i loop until i am newbie 🙂


this is a part of code that i told:

Function 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 $SYSDIR\kbdfa.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#
Use IsWindow on $0. Again put in a Sleep 500 and a counter so you don't loop forever.

Stu
mazdakam#
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?
mazdakam#
i write it with Do while but it didn't work what is wrong with it:
Function 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
     
 [B] ${LoopUntil} $0 == '1'[/B] 
FunctionEnd 
how can i tell LoopUntil window is not pop?
mazdakam#
i try to use for and while but i couldn't would you plz help more or write this loop for me?
mazdakam#
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

Function 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
Function 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#
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
Afrow UK#
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#
i make a win Macro for an alternative to close WFP maybe it helps someone 🙂
you can download it in attachment
mazdakam#
i write it with Iswindow and it works too as you told 🙂
Function 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