Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Setting service priority - How to?

 I have my own application which is running as service.
  I set its priority as IDLE using this statement.

  SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);

  I am using <u>apache</u> as one of the <u>service</u> used by my application.
  I want to set apache's priority as IDLE_PRIORITY_CLASS.

  How to do this? I can't run this through the batch file or using start command. I am starting these services when Installing my application.

  In some the thread, somebody told that Micro$oft doen't support to change the priority of a service.
  But using www.sysinternels.com 's Process Explorer, It can be set the priority for services also.

  So, it is possible to change the prority of a service programatically.

  How to do this?

  Any type of Ideas will be appreciated.
0
aravindtj
Asked:
aravindtj
  • 3
  • 2
1 Solution
 
AlexFMCommented:
Try to open this service process using OpenProcess with PROCESS_SET_INFORMATION flag, and change it's priority.
0
 
Svetlin_PanayotovCommented:
AlexFM is right but when setting the priority for another process - you must find it first.So you'll have something like:

#include <TlHelp32.h>

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe  = {0};
pe.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe))
return FALSE;
do
{
//find your process
//and set its priority by calling OpenProcess and SetPriorityClass
}
while (Process32Next(hSnapshot, &pe));

Also for more info - there's sample in Platform SDK- just look at the help for CreateToolhelp32Snapshot

Svetlin


0
 
aravindtjAuthor Commented:
Hi AlexFM and Svetlin Panayotov,
 Thanks for your reply.
 But, I am starting the application by OpenProcess method.

 I am starting a application, apache.exe as a service in my application.
I am using creating the service by CreateService method by giving the propreties
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS.
All this is made at my product installation process.
But, I need to run it as a service which is starting at boot time.
I am using StartService method to start that service.
Now, how can I set the priority?

Thanks in advance.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Svetlin_PanayotovCommented:
So this should only make it easier - just use the handle returned from OpenProcess and pass it to
SetPriorityClass.

Svetlin
0
 
aravindtjAuthor Commented:
Hi Svetlin_Panayotov,
 Thanks for reply.
 I am running the Apache as a service. There are some other Apache server is running on other ports.
 Bow, when I am listing the processes, there are 2 Apache services are started. Now, How can I get the Apache service I am running for my own purpose?

 Thanks in advance.
0
 
Svetlin_PanayotovCommented:
I can think of two possible solutions - the easier - if you're starting Apache with OpenProcess - you have the handle - and don't need to search for the process.If you don't have the handle - well before you start your instance of Apache - do a similar search and keep the PIDs for all instances of Apache you find.The PID actually is the th32ProcessID field in PROCESSENTRY32 struct.Finding your instance then is easy - it's the one that does not match any of the PIDs above.
Hope this'll work for you.

Svetlin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now