title: How to start my Windows Service at RunTime or at OnAfterInstall
body: <p><em>History</em></p>
  
  <p>I am building a <code>Windows Service</code> as part of my <code>Platform Application</code> to handle updates and server functions, so it <em>can</em> be installed in machines different than where the <code>Client Application</code> is installed. It uses UDP to send and receive broadcast messages, and TCP to to handle more sensitive and most important messages.</p>
  
  <p><em>Objective</em></p>
  
  <p>I want that my Application could be easily installed by the end user, just by copying the executable files in the computers and when executing them. The main application should verify if the user is an administrator, create the configuration files, and then install the Windows Service and run it, so when non administrative users log in, they won't receive any error from my Application regarding administrative rights. The goal is to make most configurations without the need a present technician, since database will be remote.</p>
  
  <p><em>Problem</em></p>
  
  <p>My Service is being installed normally with the command <code>MyService.exe /install</code> but it is not starting automatically. The only way to start it is to go on <code>Control Panel &gt; Admin Tools &gt; Services</code> and do it manually. I tryed to call <code>net start MyService</code> through my application but I receive <code>invalid service name</code> at the shell. I tryied the <code>executable name</code>, the <code>display name</code> and the <code>object name</code> of the service, but none of them worked. This is the object of my TService:</p>
  
  <pre><code>object ServiceMainController: TServiceMainController
    OldCreateOrder = False
    OnCreate = ServiceCreate
    DisplayName = 'PlatformUpdateService'
    Interactive = True
    AfterInstall = ServiceAfterInstall
    AfterUninstall = ServiceAfterUninstall
    OnShutdown = ServiceShutdown
    OnStart = ServiceStart
    OnStop = ServiceStop
    Height = 210
    Width = 320 
  </code></pre>
  
  <p><em>Question</em></p>
  
  <p>What should I do to start my service by the code and not by the user hands? It would be the best if I could do it inside my client application, or when by itself after the <code>OnServiceAfterInstall</code> call.</p>