title: Remote OpenSCManager fails with access denied
body: <p>I am attempting to control a service on a remote machine using the following code:</p>
  
  <pre><code>// Error checking omitted for brevity
  HANDLE hToken = NULL;
  // user = username with no domain specification
  // domain = targetmachine when targetting computer outside of domain
  LogonUser(user, domain, password,
      LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_WINNT50, &amp;hToken);
  
  ImpersonateLoggedOnUser(hToken);
  
  SC_HANDLE hSc = OpenSCManager(targetmachine,
                      SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
  </code></pre>
  
  <p>This works fine when run from a computer within our local domain and targetting a machine on the same domain, both when using the credentials from the currently logged on user as well as when using other credentials.</p>
  
  <p>However, when I attempt to target a machine that is not on any domain, the <code>OpenSCManager</code> call fails with access denied if I specify anything other than <code>SC_MANAGER_CONNECT</code> as the desired access. Targetting a domain computer from a computer that is outside the domain works (using user/domain/password combination for a domain user that is a local administrator on the target machine). Targetting a computer outside the domain from a computer outside the domain does not work.</p>
  
  <p>The user/password is for a member of the administrator group on the target computer, so there should not be a problem with the account rights.</p>
  
  <p>I've checked the scmanager security descriptor using <code>sc -sdshow scmanager</code> and it is identical for the domain computer and the non-domain computer. Both are running Windows 7 64-bit.</p>
  
  <p>I've also tested to use <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553" rel="nofollow">psexec</a>, which has the same symptoms, i.e. works fine between domain computers but not when targetting non-domain computer.</p>
  
  <p>I have also tested to disable RPC over TCP on the target machine and rebooting it, as this is <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd578505%28v=vs.85%29.aspx" rel="nofollow">described as a possible cause for access denied errors</a> but this does not appear to help. I've also tested to disable the Windows Firewall on the targetmachine, but no change.</p>
  
  <p><strong>Is there some setting that needs to be enabled in order for remote configuration of services to work?</strong></p>