1
Answer

External Process via windows service

Ask a question
vakar yusuf

vakar yusuf

16y
4.4k
1

Can anyone help? I have been struggling with creating a service which calls an external process but it just doesn't work. Please see attached code. The service installs and starts and stops fine but the call to the external process does not work.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace ExternalCommand
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            System.Diagnostics.Process.Start(@"c:\windows\system32\notepad.exe");
        }

        protected override void OnStop()
        {
            System.Diagnostics.Process.Start(@"c:\windows\system32\cmd.exe");
        }
    }
}


Answers (1)
Next Recommended Forum