Solved

Setting service priority - How to?

Posted on 2004-10-20
6
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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