Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try what leppie suggested in his comment, if it doesn't work you need to tell us which line is throwing exception - when you're creating ServiceController, when you're trying to start it or somewhere else.</p> <p>Btw, you shouldn't call sc.Start() if the service is paused, you should call sc.Continue().</p> <p>Also, it is probably better idea to use <strong>using</strong> construct than try/finally, like this:</p> <pre><code>private void StartService(string WinServiceName) { try { using(ServiceController sc = new ServiceController(WinServiceName,".")) { if (sc.ServiceName.Equals(WinServiceName)) { //check if service stopped if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped)) { sc.Start(); } else if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Paused)) { sc.Continue(); } } } } catch (Exception ex) { label3.Text = ex.ToString(); MessageBox.Show("Could not start " + WinServiceName + "Service.\n Error : " + ex.ToString(), "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } } </code></pre> <p>That way you don't need to call sc.Close() yourself (btw, you need to call Close only Dispose is redundant - Documentation for Close: Disconnects this ServiceController instance from the service and frees all the resources that the instance allocated.)</p> <p><strong>EDIT</strong>: <img src="https://i.stack.imgur.com/oLCDO.png" alt="alt text"></p> <p>Right click on your exe file in Explorer and choose Run As Administrator. In Windows 7, unless you have UAC (User Access Control) turned off you're not running programs as administrator until you explicitly request/or you are asked to do so.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload