Question

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:

//all variables are initialized correctly  
int status = 0;        
status = LogonUser(lpwUsername,        
               lpwDomain,         
                   lpwPassword,          
                   LOGON32_LOGON_NEW_CREDENTIALS,       
                   LOGON32_PROVIDER_DEFAULT,   
                   &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

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?

Was it helpful?

Solution

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.

OTHER TIPS

Rather than rolling your own, why not just use the SC built-in command?

OK, problem resolved (not really very good, but rather OK). I used WNetAddConnection() to ipc$ on remote machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top