Windows Security window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
helloguys
Posts: 5
Joined: 13 May 2018, 09:32

Windows Security window

Post by helloguys » 19 Oct 2019, 20:21

Hi,

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 

Attachments
2.png
2.png (159.67 KiB) Viewed 1468 times
1.png
1.png (460.95 KiB) Viewed 1468 times

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Windows Security window

Post by AHKStudent » 19 Oct 2019, 21:57

Security window blocks the requests, AHK will send it, but it does not mean it will get accepted.

helloguys
Posts: 5
Joined: 13 May 2018, 09:32

Re: Windows Security window

Post by helloguys » 20 Oct 2019, 06:20

However, I can use the following code to close the security window.

Code: Select all

f1::

winclose, A

return

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Windows Security window

Post by AHKStudent » 20 Oct 2019, 08:49

helloguys wrote:
20 Oct 2019, 06:20
However, I can use the following code to close the security window.

Code: Select all

f1::

winclose, A

return
I thought its a UAC window, sorry

gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: Windows Security window

Post by gregster » 23 Oct 2019, 04:25

helloguys wrote:
20 Oct 2019, 06:20
However, I can use the following code to close the security window.

Code: Select all

f1::

winclose, A

return
If Winclose, A works in this case, there is most likely some problem with the wintitle you are using in your actual script, that means, it might not be specific enough.

If I look at your screenshot, I see that Window Spy reports Windows Security as the wintitle text, but in the script you are only using ahk_class Credential Dialog Xaml Host

Yes, WinKill is executed at some point, but it only (tries to) kill(s) one window. If there is more than one matching window with ahk_class Credential Dialog Xaml Host, you might miss the right one.

Perhaps try to replace the A in your hotkey with a more specific wintitle, like

Code: Select all

F1::WinClose, Windows Security ahk_class Credential Dialog Xaml Host
(Assuming that there is only one window that matches this title.)
Push the hotkey multiple times - it might close eventually, if there are multiple matching windows... or better try:

Code: Select all

F1::				; press F1 while the target window exists
WinGet, var, Count , ahk_class Credential Dialog Xaml Host
msgbox % var
WinGet, var, Count , Windows Security ahk_class Credential Dialog Xaml Host
msgbox % var
return
If there is more than one matching window in both cases, we might need to find more specific and/or additional criteria... if the first msgbox shows multiple and the second one only 1 match, then definitely go with the more specific wintitle.

Post Reply

Return to “Ask for Help (v1)”