You must Sign In to post a response.
  • Category: .NET

    How to start windows service from winform on button click event ?

    I am working on windows service , i made winform which has 1 button and , I want a scenario like following,

    When i will install windows service project forms shortcut will create on desktop and this form has 1 button which when clicked it starts windows service , and then i will minimize this form and this form icon needs to be display in system tray and form disappears from taskbar. How could i make it possible i found way for windows form application but how could i do that for windows service?

    Thanks!!
  • #762230
    Hello Priyanka,

    Refer the below code :

    ServiceController controller = new ServiceController("serviceName");
    if (controller.Status==ServiceControllerStatus.Running)
    controller.Stop();
    if (controller.Status==ServiceControllerStatus.Stopped)
    controller.Start();

    You can go through this link for your referece :

    http://www.csharp-examples.net/restart-windows-service/


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762231
    I tried this way but wrote above lines in form but form doesnt appears after installing service

  • #762250
    Hello Priyanka,

    You can go through the below links for your reference :

    http://www.coretechnologies.com/products/AlwaysUp/Apps/RunWinFormsAppAsAService.html


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments