Reputation: 155
I found how to create and start a background process, how to add it to startup and so on. Quite simple.
The only step I need is how to increase the priority of the process I created at startup.
I saw that, from PowerShell, I can type:
$prog = Get-Process -Name backgroundTaskHost
$prog.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::High
and this works nice, I can check it running the command:
Get-Process | Format-Table -View priority
How to start the process with an higher priority? Is there any setting, command, or another method that allow to create at startup an higher priority background process?
Upvotes: 0
Views: 961
Reputation: 9720
There are 11 levels of the task. RealTime
has the highest priority, its value is 0, is higher than High
. You can start the process with an higher priority by running a PowerShell Script on Startup. You can follow these steps:
First, create a new file, name it StartupScript.ps1 and add the following lines of PowerShell code:
$prog = Get-Process -Name backgroundTaskHost
$prog.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::RealTime
Second, create a simple batch (*.bat) file that will execute the PowerShell script. Create a new file, name it “Startup.bat” and populate it with the following code:
powershell -command "C:\StartupScript.ps1"
Third, move the script and batch file to the IoT device. You can access IoT disk by File Explorer, enter following line in address bar(use your Raspberry Pi's name or IP address instead of here "minwinpc"):
\\minwinpc\C$
After that, you will see it like this picture shows:
Fourth, establish a PowerShell session with your IoT Core device and add the “C:\Windows\System32” folder permanently to your path by executing the following command:
setx PATH "%PATH%;C:\Windows\System32"
Add a startup scheduled task by executing the following command:
schtasks /create /tn "Startup PowerShell" /tr c:\Startup.bat /sc onstart /ru SYSTEM
Finally, reboot your device. When your device comes back online you can check the result by running the following command:
Get-Process | Format-Table -View priority
Upvotes: 2