title: Service not started exception when running C# program at startup
body: <p>I have a system tray application which gets installed and starts running from a logon script.  </p>
  
  <p>The program is failing on startup because it says that a service is not started but I don't know which one it is.  </p>
  
  <p>I thought it was the RPC service (name=RpcSs).  Here is what I tried but didn't work:</p>
  
  <pre><code>string ServiceName_Rpc = "RpcSs";
  ServiceController controller = new ServiceController(ServiceName_Rpc);
  controller.WaitForStatus(ServiceControllerStatus.Running);
  </code></pre>
  
  <hr>
  
  <blockquote>
    <p>The Server service is not started. (Exception from HRESULT: 0x80070842)</p>
    
    <p>at System.DirectoryServices.DirectoryEntry.RefreshCache()
       at System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit()
       at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
       at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
       at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable<code>1 identityType, String identityValue, DateTime refDate)
       at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
       at System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
       at System.DirectoryServices.AccountManagement.AuthZSet.get_CurrentAsPrincipal()
       at System.DirectoryServices.AccountManagement.FindResultEnumerator</code>1.get_Current()
       at System.Linq.Enumerable.WhereEnumerableIterator<code>1.MoveNext()
       at System.Linq.Enumerable.Any[TSource](IEnumerable</code>1 source)</p>
  </blockquote>