Trying to use AutoHotkey to close this prompt as it comes up,
i'm closing the window based on Titles, that mean any other windows credential request will get auto closed also, is there any way that i can identify that this popup prompt is generated by Outlook2016 and only then the script can close the window?
OS: Windows 10
Script:
#NoEnv
#Persistent
SetTimer, ClosePopup, 250
return
ClosePopup:
WinClose, Windows Security
return
i also tried VBS, but 2 issue, i also cant make sure this prompt is from outlook and the second is that the script wont loop
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("Windows Security")
If ret = True Then
wshShell.SendKeys "%{F4}" 'ALT F4
Exit Do
End If
WScript.Sleep 500
Loop
This should work:
WinClose Windows Security ahk_exe outlook.exe
Related
I'm automating process of connection to remote PC which includes VPN+SSH+VNC and ssh stage automatization opens too much new windows instead of one expected.
Code:
Set oShell = CreateObject("WScript.Shell")
oShell.Run("""G:\Git\git-bash.exe""")
oShell.AppActivate "MINGW64:/"
Dim command
command = "ssh -A username#adress options~"
oShell.SendKeys command
Opens from 3 to 5 git-bash instances instead of 1.
Sending keys works as intended in 1 of this 3-5 window. How to prevent opening others?
oShell.Run(oShell.ExpandEnvironmentStrings("%COMSPEC% /C (start G:\Git\git-bash.exe)")) should help.
Might also try adding a WScript.Sleep 3000 before calling oShell.AppActivate to give the OS time to launch git-bash.exe and its dependencies.
Hopefully, drive G: is a local drive. If not, increase the Sleep time to give any anti-virus time to scan the process.
Consider:
Dim WSHShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "MSTSC /v:servername"
WScript.Quit
I am able to open the RDP popup and give a server name to connect to. I need to provide the username, password, and click OK. Is there a way to achieve this from VBScript?
You can use the following code:
Dim objShell, strMachineName, strUserName, strUserPwd
set objShell = createObject("wscript.shell")
strMachineName = "enter-machine-name"
strUserName = "enter-your-user-name"
strUserPwd = "enter-user-password"
objShell.Run "cmdkey /generic:"&strMachineName&" /user:"&strUserName&" /pass:"&strUserPwd
objShell.run "mstsc /v: "&strMachineName
set objShell = Nothing
Reference on cmdkey
I have tested this on Windows 7 and it works.
I can suggest two options.
1: You can save an RDP connection (see picture below) and just run the new .rdp file from WshShell. After you create the .rdp file, you will have to log into it the first time, enter your credentials, and check the "Remember My Credentials" option.
2: You could use the SendKeys method. It is ugly but works. The downside is the password is left in the code, so you may want to look into encryption if you go this route. You may also need to tune a wait (sleep) for waiting for the popup to come up.
WScript.Sleep 5000 'Sleeps for 5 seconds
SendKeys “{TAB}”, 1 'Focus to the computer name
SendKeys "ServerName", 1
SendKeys "{TAB}", 1 'Focus to the user name
SendKeys "Password", 1
SendKeys "{ENTER}", 1 'Connect
The script I created below opens a number of virtual machines whilst the script is running the local machine's keyboard and mouse is locked via the shortkeys entry of the script CTRL ALT + F. When the script is finished I would like the keyboard and mouse to unlock using the same function.
Note that even though the keyboard is locked the hot keys to unlock the keyboard and mouse are still active these are CTRL ALT + F.
The script runs perfectly but does not unlock the keyboard and mouse, please can anyone see any issues with this script?
Dim shell
Set shell = wscript.CreateObject("Shell.Application")
set x = CreateObject("Wscript.shell")
x.sendkeys("^%{f}")
shell.Open "C:\Program Files\Oracle\VirtualBox\VirtualBox.exe"
WScript.Sleep 3000
shell.Open
"\\leeds.smoothwall.net\DFS\homefolder\steve.newton\Documents\Local
Automation scripts\VBS files\Paths\NetworkGuardian.lnk"
WScript.Sleep 120000
shell.Open
"\\leeds.smoothwall.net\DFS\homefolder\steve.newton\Documents\Local
Automation scripts\VBS files\Paths\IE11 - Win10 Admin.lnk"
WScript.Sleep 20000
shell.Open
"\\leeds.smoothwall.net\DFS\homefolder\steve.newton\Documents\Local
Automation scripts\VBS files\Paths\IE11 - Win10.lnk"
WScript.Sleep 20000
Set shell = wscript.CreateObject("Shell.Application")
set x = CreateObject("Wscript.shell")
x.sendkeys("^%{f}")
WScript.Sleep 2000
MsgBox "Automation Startup complete"
I found the solution, when the virtual machines started they automatically sent the user controls to the active windows, I turned this option off and now the script works perfectly.
I am working on a VBScript where it activates an application, sends a password to that application and minimizes the application. My script fails sending the keys. The application does not get the password, but when I double-click on the script it receives the password and minimizes. I don't know where the error is.
It's called like this:
InitliszeUSb.bat:
pause
START %myDrive%"RunSanDiskSecureAccess_Win.exe"
pushd %~dp0
ping 10.10.10.10 -n 1 -w 10000 >nul
start /b "" cscript "D:\min.vbs"
Min.vbs:
Option Explicit
Dim oSHL : Set oSHL = CreateObject("WScript.Shell")
oSHL.AppActivate "SanDisk SecureAccess"
oSHL.SendKeys "pass1_word~" 'Enters Password
WScript.Sleep(3000)
oSHL.SendKeys "% n" 'Minimises the window
WScript.Quit
In Windows 7, I experienced issues when using SendKeys to send keys to other apps (the way like you do), when SendKeys is not running in elevated process. Sometimes the macro/script works 100%, sometimes it looks like keystrokes are getting lost. The only way around I found for that was running sender application (or script) elevated (i.e. "As Administrator").
I'm using a VBScript to SendKeys to a Cisco Client because it prompts for a username and password. However, I am having problems getting the command prompt focused.
I added AppActivate before every SendKeys command, but normal computer usage often breaks the focus in the time between these commands.
How can I ensure the command prompt has focus before sending keys?
Dim host, username, password, pathToClient
host = "host"
username = "username"
password = "password"
pathToClient = "C:\Program Files {(}x86{)}\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe"
Set ws = WScript.CreateObject("WScript.Shell")
ws.run("TASKKILL.exe /F /IM vpnui.exe"), 0, false
ws.run("cmd.exe"), 2, false
WScript.Sleep 300
ws.AppActivate("Command Prompt")
ws.SendKeys """" & pathToClient & """ connect " & host & "~"
WScript.Sleep 1000
ws.AppActivate("Command Prompt")
ws.SendKeys(username & "~")
WScript.Sleep 50
ws.AppActivate("Command Prompt")
ws.SendKeys(password & "~")
ws.run("TASKKILL.exe /F /IM cmd.exe"), 0, false
With VBScript you can't. AppActivate is the only method available in VBScript to place the focus on a particular application, and it doesn't ensure the focus stays there. That's the exact reason why SendKeys shouldn't be used for automation anyway. Try something like AutoIt instead.
Or might setting Auto Connect on Start be an option, since you're apparently using AnyConnect?
Auto Connect on Start—AnyConnect, when started, automatically establishes a VPN connection with the secure gateway specified by the AnyConnect profile, or to the last gateway to which the client connected.
I used AutoHotKey to solve my issue. Here's my code:
host := "my.host.domain"
username := "myUsername"
password := "myPassword"
pathToClient = "C:\...\vpncli.exe"
DetectHiddenWindows, on
Process, Close, vpnui.exe
run, cmd.exe,, Hide
Sleep 100
ControlSend,, %pathToClient% connect %host%{Enter}, ahk_exe cmd.exe
Sleep 1000
ControlSend,, %username%{Enter}, ahk_exe cmd.exe
Sleep 50
ControlSend,, %password%{Enter}, ahk_exe cmd.exe
;Process, Close, cmd.exe