Last active
May 28, 2024 19:46
-
-
Save dlennox24/511f09c10a4fc2dbcb8e49d5f521875b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MUST BE RUN AS AN ADMIN | |
# this script sets the affinity and priority of a given process | |
# orginally developed to fix mic audio issues in Discord while using VoiceMeeter | |
# can be set up to run on system startup via Windows Task Scheduler | |
# script will attempt a set number of times with a delay inbetween before exiting | |
$processName = "audiodg" | |
$priority = "HIGH" | |
$affinity = 2 | |
$sleepDelay = 5 # time in seconds | |
$attempts = 12 | |
$totalTime = $attempts*$sleepDelay+$sleepDelay | |
Write-Host "`nSetting process ``$processName`` to priority ``$priority`` and affinity to ``$affinity``.`n" | |
while($attempts -gt 0) { | |
if(Get-Process $processName -ErrorAction silentlycontinue) { | |
$process = Get-Process $processName | |
$process.ProcessorAffinity = $affinity | |
$process.PriorityClass = $priority | |
Write-Host "$processName is running! Set priority and affinity" -ForegroundColor Green | |
Write-Host "`nClosing in 5 seconds...`n" | |
Start-Sleep -s 5 | |
stop-process -Id $PID | |
} | |
Write-Host "$processName is not running! Trying again in $sleepDelay seconds. $attempts retry attempts remaining." -ForegroundColor Yellow | |
$attempts-- | |
Start-Sleep -s $sleepDelay | |
} | |
Write-Host "`nAffinity and Pritory not set for ``$processname``" -ForegroundColor Red | |
Write-Host "Process did not start in $totalTime seconds. Try increasing the delay and/or retry attempts if your system takes longer to start ``$processName```n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
* = optional
Set up the foundation
C:\startup-scripts
) and place this script in it.ps1
as its file typeTask Scheduler Library
(i.e.,startup-scripts
)Create Task...
Creating the Task
General tab
Run only when user is logged on
Run with highest privileges
Configure for:
dropdown, selectWindows 10
Triggers tab
New...
in the Triggers tabBegin the task:
dropdown, selectAt Log on
Any User
is selected in the Settings section andEnabled
is checked in the Advanced settings sectionOK
Actions tab
New...
in the Actions tabProgram/Scripts
line, addpowershell.exe
Add arguments (optional):
, add-NoExit -ExecutionPolicy Bypass <pathToPs1Script>
<pathToPs1Script>
is the location of the script you set in step #1 (i.e.,C:\startup-scripts\voicemeeter_audiodg_fix.ps1
)-ExectuionPolicy Bypass.
This disables security safeguards, so ensure you trust the author before you run them.OK
Conditions and Settings tabs
Testing the Script
This script can be tested by restarting the computer or right-clicking on it in the Task Scheduler and selecting
Run
. A PowerShell prompt should come up and show the script's process. The greenaudiodg is running! Set priority and affinity
message means the script was successful and the dialog will automatically close after 5 seconds.