Solved

Setting service priority - How to?

Posted on 2004-10-20
6
398 Views
Last Modified: 2010-04-24
 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
Comment
Question by:aravindtj
  • 3
  • 2
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 12367458
Try to open this service process using OpenProcess with PROCESS_SET_INFORMATION flag, and change it's priority.
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12367689
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
 
LVL 3

Author Comment

by:aravindtj
ID: 12441933
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 6

Expert Comment

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

Svetlin
0
 
LVL 3

Author Comment

by:aravindtj
ID: 12460532
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
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 500 total points
ID: 12460836
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question