I have scheduled task that should run every two hours, with the following command line action:
- Program:
mshta
- Arguments:
vbscript:Execute("CreateObject(""Wscript.Shell"").Run ""powershell -NoLogo -Command """"& 'X:\Path\To\Custom\powershellScript.ps1'"""""", 0 : window.close")
Every two hours, instead of the task getting run, i'm getting:
and in Defender history:
I don't want to stop Windows Defender, because of potential security implications of doing so. Is there a way to add exclusion in Defender to ignore the task?.
I tried adding both script path, folder, mshta.exe
and powershell.exe
to exclusions, also ps1
to file types. Nothing works.
By the way, Defender doesn't remove the task, or the script that should be run, just stops it from running.
Clarification:
It must be run in background, no window should pop out when the task is run, it has to be run with the user if he's logged in, i don't want to store password/run with other user account or highest privileges.
The script has to be executed as the logged in user. The purpose of it is to change the wallpaper for the logged in user to downloaded one (
$picturePath
variable). Excerpt:
$registryPropertyPath = "HKCU:\Control Panel\Desktop\"
$registryPropertyName = "Wallpaper"
$wallpaperProperty = (Get-ItemProperty -Path $registryPropertyPath -Name $registryPropertyName).WallPaper
if ($wallpaperProperty -ne $picturePath) {
Set-ItemProperty -Path $registryPropertyPath -Name $registryPropertyName -Value $picturePath
for ($i = 0; $i -lt 20; $i++) {
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
}
}
wscript
rather than MSHTA? 2) avoiding the PowerShell layer and doing everything via VBScript? It can read and write registry, too.