Is there a way to move arrow key to left on Windows Popup? - autohotkey

I am writing a script which will allow PowerShell to run in admin mode but when I run Set-ExecutionPolicy Bypass, Windows displays a popup and I use my left arrow key to move to the yes button and press enter.
The problem I am facing is that it does not move to the left or press enter when I run the script as follows.
RunWait PowerShell.exe -ExecutionPolicy Bypass -NoExit -Command "C:\Users\%A_UserName%\Desktop\Script.ps1";
Send {Left}
Sleep, 5000
Send {Enter}
I am expecting it to actually move to the OK button on the left and press enter but nothing actually happens.

If you run PowerShell in admin mode your script needs also to be run
in this mode.
Unlike Run, RunWait will wait until the program (in
this case PowerShell.exe) finishes before continuing (= sending
commands to the popup window). To bypass this problem use SetTimer.

Related

Make ms-edge Window full screen (F11, normally) via powershell script

I'm trying to make ms-edge Window full screen (F11, normally) via powershell script.
This is an example of the powershell script I'm using to start edge:
Start-Process -FilePath msedge -ArgumentList '--new-window www.google.com'
This works fine. However, I want the edge window to be full-screen, like what happens when you press F11 while in the browser. This action cannot be dependent on the windows user or individual user ms-edge profile settings. I need it to be done from the script - if that is possible - so the action is the same for all users when they run the script.
Start-Process msedge.exe https:\\google.com -WindowStyle Maximized
if you're looking to start it in Full Screen mode, you can use the start-fullscreen switch.
--start-fullscreen.
So, it would be:
Start-Process -FilePath "msedge.exe" -ArgumentList '--new-window www.google.com --start-fullscreen'
Here are the content switches / source you can use, where start-fullscreen is shown as well.
I also recently wanted to open a web page in full-screen mode simply via a shortcut in autostart.
--start-fullscreen did not work, for whatever reason.
--kiosk www.google.com --edge-kiosk-type=fullscreen worked, but Edge is started in private mode and some functions no longer work.
Now I found out that --start-fullscreen does not work in connection with the "startup boost" of Edge. As soon as this is switched off in the settings, the parameter works again.

Powershell script with "-WindowStyle Hidden -NonInteractive" still causes a console window to open momentarily

I'm working around an annoyance with the Win 10 start menu that can't handle multiple shortcuts (start menu tiles) to the same executable command. I want to have individual start menu items to open named PuTTY sessions using PuTTY -load SessionName
So, I have created a small powershell (PS) script file for each session like:
# ----Open named PuTTY session----
$PF= ${Env:ProgramFiles}
$exe= "Other\PuTTY\putty.exe"
$session= "Servername (login)"
$PuTTY= Join-Path $PF $exe
& $PuTTY -load $session
I can then create a shortcut to this script, with the shortcut target set to-
powershell.exe <path to ps1 script file>
and pin the shortcut to the start menu.
This works well, but as the script runs you can see a powershell console window flick open and then close as the script runs. I want to get rid of this annoying flicker of the PS console window.
I have experimented with adding the -WindowStyle Hidden and/or -NonInteractive options to the command line in the shortcut, but the annoying flicker of the powershell console still happens.
I would have expected -WindowStyle Hidden to make PS run in the background with no display window. Is that not the case? or is there another way to achieve a truly "invisible" PS script?

Can I disable select mode in a PowerShell script?

PowerShell default is that when you click inside the PowerShell console, PowerShell goes into "select mode" and pauses the script until you hit space, enter or escape.
I have a Script with an infinite-loop while ($true) {} which should always run, how can I tell PowerShell to not stop the script when someone accidentally clicks into the PowerShell window?
In Windows PowerShell, this can be achieved by:
Right click on PowerShell window icon;
Select "Properties";
Disable "Edit Options" > "QuickEdit Mode".

Launch powershell script with keyboard hotkey

I want to execute a powershell script (ps1-file) with a hotkey on my keyboard (CTRL + SHIFT + F for instance).
I managed to create a shortcut of the script (right click in explorer > new > shortcut). The shortcut's target is: "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "PATH_TO_THE_SCRIPT" ".
When I execute the script manually (by double-clicking the shortcut), it works like a charm. But when I try to assign a "Shortcut key" in the Shortcut Properties (CTRL + SHIFT + F) and press the shortcut key I just defined, nothing happens. What's the matter?
I'm quite sure it has something to do with security policies. But I don't know what exactly it is.
This is my Execution-Policy:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Unrestricted
LocalMachine Unrestricted
Any help is appreciated.
That's it. As soon as I move the shortcut file to the desktop and redefine the "shortcut key", the shortcut key works!
Is there a particular reason, why the shortcut has to be on the desktop?
Fist start PowerShell with run as administrator .
then type this command on it :
Set-ExecutionPolicy Bypass -Force
after this you can run all script.
remember if you use Powershell_ise (IDE for powershell) don't use 86x when you're OS is 64 bit.and if you're directory in desktop you should fist set you're directory with :
cd "enter desktop directory"

PowerShell: Kill and message prompt by window title

Is there a way in powershell to listen for message prompts produced by software that will terminate the message prompt?
For instance, if I am using an application and then it prompts a message for the user to click "OK". IS there a way I can use PowerShell to find that "window title" to kill that prompt?
You can use this two commands:
$TitleToKill = "CMD"
get-process | where-object {$_.MainWindowTitle -eq $TitleToKill} | stop-process
I decided to go with AutoIt.
I noticed AutoIt has an AutoIt Window Info tool that you can hover you mouse over the Message Prompt. Then the Window Info will give you the Windows Title, Text and CLASS ID if it has one.
Then you can write a simple autoit script that will Wait for the message prompt and close it.
Example Script that I'm using.
WinWait("[CLASS:#32770]", "Cannot sign in to Lync because this sign-in address was not found. Please verify the sign-in address and try again. If the problem continues, please contact your support team.", 0)
WinClose( "Lync")
WinWait will wait for the prompt with that specific message and close it. Once it performs the action and closes the window. The EXE will shutdown and stop running, of course unless you program it not to close and loop.