Powershell won't send keys once locked

Viewed 348

I'm attempting to create an autoclicker that can run in the background, or while other users use the computer and the account that the autoclicker is on is not logged off of (I'm using Windows 10)

I've tried running the script with administrative privileges. However, this still returns the same issue. I believe it may be an issue with Windows security and not powershell itself, however I do not know any other methods.

add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms

$wshell = New-Object -ComObject wscript.shell;

do {
[Microsoft.VisualBasic.Interaction]::AppActivate("Program")
[System.Windows.Forms.SendKeys]::SendWait("m");
start-sleep -Milliseconds 1050
} while ($true)

This is the output:

Exception calling "SendWait" with "1" argument(s): "Access is denied"
At C:\Users\me\Desktop\ASI.ps1:8 char:1
+ [System.Windows.Forms.SendKeys]::SendWait("m");
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : Win32Exception

Is there any method that can simulate key input, even if the desktop is locked?

1 Answers

You will not be able to complete what you are attempting to do natively.

You will be able to create a Virtual Machine that may be able to continue running while the computer is locked. That way you can run all your scripts and game inside the virtual machine, lock the physical machine and away you go.

Even running it as a scheduled task with "Run whether user is logged on or not" checked, it will not give you the desired results.

Related