I have a simple keep-alive function that will press ScrollLock every 60 seconds to stop my work laptop from going to sleep (altering power-management settings is not an option here as those settings are restricted to me on this work system), but this script is dependent upon the console that starts the function from always being open. Can someone advise how to get this function to:
• spawn a completely independent process (i.e. not a child process) that will continue to exist even after the console that runs the function closes?
• Make that new process completely silent i.e. starts invisibly as a background process that I can only see by running Get-Process?
Being able to create independent (non-child) processes in this way would be good for many other situations I think - that ability to create an independent process that does not close with the calling console would be really useful.
function KeepAlive {
$wsh = New-Object -ComObject WScript.Shell
while($true) {
$wsh.SendKeys('{SCROLLLOCK}')
Start-Sleep 60
}
}