Solved

Windows Service

Posted on 2004-03-26
7
209 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

789 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