I have this script to block the keyboard that I want to run on all domain users who logon through schedule tasks while another script checks updates:
$code = @'
[DllImport("user32.dll")]
public static extern bool BlockInput(bool fBlockIt);
'@
$userInput = Add-Type -MemberDefinition $code -Name Blocker -Namespace UserInput -PassThru
block user input
$null = $userInput::BlockInput($true)
Write-Warning "Your input has been disabled for 4 seconds..."
Start-Sleep -Seconds 4
unblock user input
$null = $userInput::BlockInput($false)
I have set the scheduled task to run as system so that it will block the keyboard. The schedule task runs fine, I have tested it with set-content but the keyboard is not blocked at all. The script runs as expected if manually run.
Is this because it is an interactive script? I have tried with different flags ie -noprofile, -noexit, -nonI but does not help.
Any advice?