Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Process priority does not work

Tags:

c#

windows

I run an Audio Repeater application which allows me to play sound through my headset & Speakers at the same time. The Application itself has an ability to set itself to "RealTime" but it only sets it to high so at the moment I have to set it myself in Task Manager.

I decided to automate this so I wrote a little script in C# that would change the process priority for me (That I would add to start up once I've finished)

namespace ProcessRealtime
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] processes = Process.GetProcessesByName("audiorepeater");
            foreach (Process proc in processes)
            {
                Console.WriteLine("Changing Priority for: "+proc.Id+" To RealTime");
                proc.PriorityClass = ProcessPriorityClass.RealTime;
                if (proc.PriorityClass == ProcessPriorityClass.RealTime)
                {
                    Console.WriteLine("Worked");
                }
            }
            Console.ReadLine();
        }
    }
}

The problem is that it does not apply the changes. Screenshot of Desktop

Does anyone know why this will not work?

like image 681
Oliver Baker Avatar asked Dec 19 '12 02:12

Oliver Baker


1 Answers

You need to run YOUR script with administrative privilege.

like image 131
FrostyFire Avatar answered Oct 23 '22 10:10

FrostyFire