<p>I need to remotely install windows service on number of computers, so I use CreateService() and other service functions from winapi. I know admin password and user name for machines that I need access to. In order to gain access to remote machine I impersonate calling process with help of LogonUser like this:    </p>

<pre><code>//all variables are initialized correctly  
int status = 0;        
status = LogonUser(lpwUsername,        
               lpwDomain,         
                   lpwPassword,          
                   LOGON32_LOGON_NEW_CREDENTIALS,       
                   LOGON32_PROVIDER_DEFAULT,   
                   &amp;hToken);            


if (status == 0)    
{   
         //here comes a error  
}  

status = ImpersonateLoggedOnUser(hToken);     
if (status == 0)                
{     
    //once again a error     
}      

//ok, now we are impersonated, do all service work there
</code></pre>

<p>So, I gain access to machine in a domain, but some of computers are out of domain. On machines that are out of domain this code doesn't work. Is there any way to access service manager on machine out of domain?</p>

[{'answer_id': 62560, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>You can do it , the account needs to exist on the remote machine and you need to use the machine name for the domain name in the LogonUser call.</p>\n'}, {'answer_id': 101264, 'author': 'Jon Grant', 'author_id': 18774, 'author_profile': 'https://Stackoverflow.com/users/18774', 'pm_score': 0, 'selected': False, 'text': '<p>Rather than rolling your own, why not just use the SC built-in command?</p>\n'}, {'answer_id': 114935, 'author': 'Andrey Neverov', 'author_id': 6698, 'author_profile': 'https://Stackoverflow.com/users/6698', 'pm_score': 0, 'selected': False, 'text': '<p>OK, problem resolved (not really very good, but rather OK). I used WNetAddConnection() to ipc$ on remote machine. </p>\n'}]
['https://Stackoverflow.com/questions/62501', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6698/']