Solved

Windows Service

Posted on 2004-03-26
7
212 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
[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
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
Industry Leaders: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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