Old 17th November 2007, 23:41   #1
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
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 is offline   Reply With Quote
Old 18th November 2007, 06:37   #2
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
ding!
mazdakam is offline   Reply With Quote
Old 18th November 2007, 14:02   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Try FindWindow. To get the window class (if it has one) you'd need to use Spy++ or a similar tool.

Stu
Afrow UK is offline   Reply With Quote
Old 18th November 2007, 16:35   #4
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
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
....
mazdakam is offline   Reply With Quote
Old 18th November 2007, 21:44   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 19th November 2007, 05:35   #6
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
thanks for answering...

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


this is a part of code that i told:

PHP Code:
Function closeWFP
     Sleep 10000
    
;Find and close first dialog
    FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'

    
;Find and close second dialog
    FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
FunctionEnd 
PHP Code:
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

PHP Code:
Section -WFP2
;nsExec::Exec '"$INSTDIR\CWFP.exe"'
call closeWFP
SectionEnd 
so tell me how can put it too a loop thanks
mazdakam is offline   Reply With Quote
Old 19th November 2007, 14:12   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Use IsWindow on $0. Again put in a Sleep 500 and a counter so you don't loop forever.

Stu
Afrow UK is offline   Reply With Quote
Old 19th November 2007, 20:17   #8
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
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 is offline   Reply With Quote
Old 19th November 2007, 20:30   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
With LogicLib, ${For} $R0 1 1000 ... ${Next}

Stu
Afrow UK is offline   Reply With Quote
Old 19th November 2007, 22:03   #10
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
i write it with Do while but it didn't work what is wrong with it:
PHP Code:
Function closeWFP

${Do}
;
Find and close first dialog
     FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'

;Find and close second dialog
    FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'
    
Sleep 500
     
 
[B] ${LoopUntil} $== '1'[/B
FunctionEnd 
how can i tell LoopUntil window is not pop?
mazdakam is offline   Reply With Quote
Old 20th November 2007, 07:46   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You cannot do it safely without a counter. Use a For loop.

Stu
Afrow UK is offline   Reply With Quote
Old 20th November 2007, 11:36   #12
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
i try to use for and while but i couldn't would you plz help more or write this loop for me?
mazdakam is offline   Reply With Quote
Old 20th November 2007, 12:05   #13
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
Thumbs down

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

PHP Code:
Function closeWFP

nok
:
${If} 
$R1 <= 10
    Iswindow 
$0 0 ok
    FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'

    
FindWindow $"" "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
PHP Code:
Function closeWFP

${For} $R1 1 10

 
;Find and close first dialog
     FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_COMMAND},2,0)'

;Find and close second dialog
    FindWindow 
$"" "Windows File Protection"
    
System::Call 'user32::PostMessageA(i,i,i,i) i($1,${WM_COMMAND},6,0)'

Sleep 1000
${Next}
FunctionEnd 
mazdakam is offline   Reply With Quote
Old 20th November 2007, 16:59   #14
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
code:
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 is offline   Reply With Quote
Old 20th November 2007, 17:15   #15
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
Yes! it works
this is because i did not know StrCmp

Thank you so much for your time
mazdakam is offline   Reply With Quote
Old 20th November 2007, 17:17   #16
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 20th November 2007, 17:37   #17
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
i make a win Macro for an alternative to close WFP maybe it helps someone
you can download it in attachment
Attached Files
File Type: rar cwfp.rar (192.2 KB, 209 views)
mazdakam is offline   Reply With Quote
Old 21st November 2007, 03:25   #18
mazdakam
Junior Member
 
mazdakam's Avatar
 
Join Date: Nov 2007
Posts: 35
i write it with Iswindow and it works too as you told
PHP Code:
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 
mazdakam is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump