Windows Service

Posted on 2004-03-26
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!!!!
Question by:tbaseflug
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
LVL 12

Expert Comment

ID: 10688559
Check out the System.Diagnostics namespace.

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

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

Expert Comment

ID: 10688854

  Go to this page:  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.

Author Comment

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?
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 10

Expert Comment

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).
LVL 10

Expert Comment

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.

Author Comment

ID: 10700049
ptmcomp -

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

Accepted Solution

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)
            case ServiceControllerStatus.ContinuePending:
            case ServiceControllerStatus.Running:
            case ServiceControllerStatus.StartPending:
              // Service is already starting
              // Service is not running; Start


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.

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 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