I wrote a script to automatically reconnect to company VPN as it expires every 24 hours (company policy). During the VPN connect process, there's a Windows Security pop-up to prompt me select a client certificate. I shall close the pop-up window (either click OK, Cancel, or just close the window) in order to continue the process. However, AHK seems to have difficulty closing the window. Here what I did:
1) I used Windows Spy to find out the "ahk_class" of the window, as AHK seemed to having difficulty detecting the window by title. "ahk_class Credential Dialog Xaml Host" is what I got.
2) In the AHK script, I use WinWait to wait for the window. Then use WinKill (I also tried WinClose, and ControlClick) to close window.
3) Per debug log, AHK successfully detects the window, and executed the WinKill command. However the window was not closed. Same behavior as WinClose, ControlClick. Nothing seemed to happen to the window even AHK executed the command.
Here's my code. I also attached some screenshots below. Thank you for your help!
Code: Select all
SetControlDelay -1
SetTitleMatchMode, 1
Loop {
WinWait, Cisco AnyConnect,,,,Connected
If WinExist("Cisco AnyConnect","Max time exceeded")
{
ControlClick, OK,Cisco AnyConnect,Max time exceeded
run "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
}
If WinExist("Cisco AnyConnect Secure Mobility Client","Ready to connect")
{
ControlClick, Connect,Cisco AnyConnect Secure Mobility Client,Ready to connect
WinWait, ahk_class Credential Dialog Xaml Host
{
WinKill, ahk_class Credential Dialog Xaml Host
}
WinWait, Cisco AnyConnect, PIN
{
ControlSetText, Edit2, 123456
ControlClick, OK,Cisco AnyConnect,PIN
}
WinWait, Cisco AnyConnect, Accept
{
ControlClick, Accept,Cisco AnyConnect,Accept
}
}
}
Return