简体   繁体   中英

Managing Windows Service (creating, deleting, starting, stopping, arguments)

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. eg c:\\myService.exe someFileName.dat

now i am making ac# 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM