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
}
}
Best Answer
Again, as noted, if you do this, it's simply a virus type action and should be blocked.
As @HackSlash notes, that is the correct way to do this.
When you say a Windows pop-out because of this, and it should because you are starting a new shell and the shell has to launch and show as active. You can just add the WindowStyle property -minimize or -hidden switch to diminish that.
Or this approach, since even the above the window will still momentarily flash.
Or this one