Prioritizing a thread in a service does not affect

Is there any additional configuration before I can prioritize threads in a windows service?

In my service, I have several threads, each of which calls the CreateProcess() function to start an external application. I would like to prioritize threads (or processes) to normal or lower , depending on some other factors.

The problem is that the SetThreadPriority() function does not work with error 6 (invalid handle?). I pass in the descriptor obtained from PROCESS_INFORMATION::hThread (after calling CreateProcess() , of course), so I believe that the descriptor should be valid.

I also tried to set the priority for processes using the SetPriorityClass() function, which also fails.

The service is registered as a local user.

+2
source share
1 answer

Perhaps you do not have the correct permissions? The MSDN on SetThreadPriority says:

hThread [in] Knob for the thread whose priority value should be set.

The pen must have THREAD_SET_INFORMATION or Access THREAD_SET_LIMITED_INFORMATION correctly. For more information, see Security and Access Rights.

Windows Server 2003 and Windows XP / 2000: The handle must have THREAD_SET_INFORMATION permission.

+2
source

All Articles