Solved

Windows Service

Posted on 2004-03-26
7
210 Views
Last Modified: 2010-04-15
Am trying to figure out how I would start a process at the following location: "C:\Program Files\Network Associates\VirusScan\mcupdate.exe"

I need to check and see if the process is started.  if not start it, execute, then stop when completed - any help would save my day!!!!
0
Comment
Question by:tbaseflug
7 Comments
 
LVL 12

Expert Comment

by:dfiala13
ID: 10688559
Check out the System.Diagnostics namespace.

Here's a link to the Process class and its Start Method.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic.asp

And the GetProcesses static method which will tell you what's currently running...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassgetprocessestopic.asp
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10688854
tbaseflug,

  Go to this page: http://msdn.microsoft.com/vcsharp/downloads/samples/23samples/default.aspx.  You will see an item called "Interacting with a Windows Service in C#".  Download the sample code, and take a look - I think that is more what you are looking for.
0
 

Author Comment

by:tbaseflug
ID: 10689810
eternal_21 -

This does seem closer to what I am looking for - any idea on wether the same concept can applied to a process as opposed to a service - in the ability to start and stop?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:eternal_21
ID: 10690529
If you want to start and stop a process, this can all be done through the System.Diagnostics.Process class (as dfiala13 suggested).
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 10699255
You cannot start or stop a service with those methods. But you can use them to check if it's running. Use the ServiceController to stop and start services.
0
 

Author Comment

by:tbaseflug
ID: 10700049
ptmcomp -

Can you give me a quick code-level example?
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 10702104
Here is a quick example, taken from the code at the link I provided earlier.  As written it will start the Messenger service if it is not already running or starting.

### C#.NET ###

      const string serviceName = "Messenger";

      ServiceController[] AvailableServices = ServiceController.GetServices();
      foreach(ServiceController AvailableService in AvailableServices)
      {
        if(AvailableService.ServiceName==serviceName)
        {
          switch(AvailableService.Status)
          {
            case ServiceControllerStatus.ContinuePending:
            case ServiceControllerStatus.Running:
            case ServiceControllerStatus.StartPending:
              // Service is already starting
              break;
            default:
              // Service is not running; Start
              AvailableService.Start();
              break;
          }
        }
      }

###

You will need to include a reference in your project to the System.ServiceProcess assembly.  And as the code is written here, you will need a "using System.ServiceProcess" statement.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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