Solved

Setting service priority - How to?

Posted on 2004-10-20
6
395 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now