0

I have tried a lot of possibility with this code but it doesn't work. I need to check a VPN connection. If I run the code firs time it works, but if I don't restart the program and push the button secondly then the program just disappear. Any idea how to fix it? thanks.

Function VpnLoginWindow
  ${Do}
    !insertmacro VpnLoginWindow
    StrCpy $4 0
    ${If} $3 == 1
      ${Do}
        !insertmacro VpnLoginWindow
        StrCpy $4 1
        StrCmp $3 "0" 0 +2
        ${ExitDo}
      ${Loop}
    ${EndIf}
    ${If} $4 == 1
      ${ExitDo}
    ${EndIf}
  ${Loop}
FunctionEnd

!macro VpnLoginWindow
  StrCpy $5 $1
  System::Get "(i.r1) iss"
  Pop $R0
  System::Call "user32::EnumWindows(k R0, i) i.s"
  ${Do}
    Pop $0
    StrCmp $0 "1" 0 +2
    ${ExitDo}
    System::Call "user32::GetWindowText(ir1,t.r2,i ${NSIS_MAX_STRLEN})"
    StrCpy $2 $2 7
    StrCpy $3 0
    ${If} $2 == "SSL VPN"
      StrCpy $3 1
      ${ExitDo}
    ${EndIf}
    Push 1 # callback's return value
    System::Call "$R0"
  ${Loop}
  System::Free $R0
  StrCpy $1 $5
!macroend
604
  • 1
  • 1
  • Which NSIS version? – Anders Aug 01 '19 at 19:52
  • 3.04, the process working in bgworker – 604 Aug 01 '19 at 20:01
  • I can't compile this, how is the function and macro even related? – Anders Aug 01 '19 at 20:16
  • In the first loop waiting for the login window of VPN client, the nested loop waiting for the disappear, when I wrote the passwod and hit enter. After this 20 seconds loop for the VPN connection, and if OK then start some program. I needed to use bgworker plugin because without it the window not responding. The problem is when I run again without restart the program, it crashing and disappear. – 604 Aug 01 '19 at 20:33
  • I figured as much, but your function code calls VpnLoginWindowCheck but your macro is named VpnLoginWindow! – Anders Aug 01 '19 at 21:04
  • Sorry. Edited. If I put a messagebox after EnumWindows, it causes an endless loop, but only after second run. I think it's some memory problem but I didn't find anything. :( – 604 Aug 01 '19 at 21:19
  • If I place bgworker twice after another, it drop me out. I think I should do something with bgworker plugin but no idea what. Can I reload somehow or any other solution? – 604 Aug 02 '19 at 16:36

1 Answers1

0

Callbacks are tricky to get right and the plug-in is a little buggy. Also, you should not use relative jumps to jump over macros like ${ExitDo}!

!include LogicLib.nsh

!macro FindVpnLoginWindow
Push "" ; Result: Window not found
System::Store S
System::Get '(p.r1, p)ir0r0'
Pop $9
System::Call 'USER32::EnumWindows(k r9, p 0)'
${Do}
    ${IfThen} $0 != "callback1" ${|} ${ExitDo} ${|} ; <-- adjust the callback# if required
    StrCpy $0 1 ; Set callback return value, continue search
    System::Call "USER32::GetWindowText(pr1, t.r2, i ${NSIS_MAX_STRLEN})"
    StrCpy $2 $2 7
    ${If} $2 == "SSL VPN"
        Pop $2 ; Throw away old result
        Push $1 ; Result: HWND
        StrCpy $0 0 ; Set callback return value, stop enum with 0
    ${EndIf}
    System::Call $9 ; Return from callback function
${Loop}
System::Free $9
System::Store L
!macroend

Function BackgroundFindWindow
!insertmacro FindVpnLoginWindow
Pop $0
DetailPrint "Result:$0"
FunctionEnd

...

GetFunctionAddress $0 BackgroundFindWindow
BgWorker::CallAndWait
GetFunctionAddress $0 BackgroundFindWindow
BgWorker::CallAndWait
Anders
  • 97,548
  • 12
  • 110
  • 164
  • Wow thanks. I'll try it. Looks like this is what I need. I hope this working – 604 Aug 03 '19 at 14:47
  • It doesn't work for me :( I'll make it other way. I'll write password in the nsis window. This is the simplest. Thanks for your help anyway – 604 Aug 03 '19 at 18:49
  • What does "doesn't work" mean? Does the window disappear (crash)? – Anders Aug 03 '19 at 19:12
  • Yes, because first I need to wait for window then wait again. If I start this process more than one time it just disappear :( – 604 Aug 04 '19 at 09:16