1

What I am trying to do, i have an executable file (myService.exe). it is a windows service and it supports start, stop and other such options. It uses one argument (filename) and run its survices on it. e.g. c:\myService.exe someFileName.dat

now i am making a c# windows form application. I am reading filename from a textbox and on button click event i want to do this.

  1. check whether myServices.exe is installed on machine or not.
  2. if it is installed then i have to check it is in running state or not.
  3. if it is in running state then stop it.
  4. after stopping it i need to uninstall the service.
  5. after uninstalling it i want to install it again and have to give filename as the parameter of service and then run it.

How to install a windows service programmatically in C#? i have tried this but i have to give argument to the service which is not present there.

Community
  • 1
  • 1
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
  • 1
    Services don't support command line arguments. Given that you want to use a Winforms app to control it, there's strong evidence that you don't actually want to use a service. You can create a process that acts like a service in this regard (accepts command line, no user interface) by simply writing a Winforms app that doesn't create a main window. – Hans Passant Dec 02 '11 at 12:47

1 Answers1

1

Why not create a List that the windows application uses or if you are stuck on using a Windows Service application have a .config file that the windows service app uses and store the initial directory in it. using the FileInfo and DirectoryInfo and of GetAllFiles() method store the files in a List and iterate the List varList = new List(); variable object that way.

You could also make a Web Service and have the windows application consume that web service by adding a web reference the same way you would if you wanted to add a reference to an additional / 3rd party assembly. Lots of options you have

MethodMan
  • 18,625
  • 6
  • 34
  • 52