Pregunta

I use the impersonate mechanism to manage services on a distant machine I can connect to that machine with my username and password on an RDP session and start/stop services manually. I also managed to start/stop services through code using the IntPtr.Zero token in the impersonate statement, but when calling the logonuser function, I get a failure (returns token = 0 and error = 87)

here is some code:

if (LogonUser(_userName, domain, _Password, logonType (= 5), logonProvider (= 0), out token))
{
    MessageBox.Show("success!");
    return token;
}
else
{
    MessageBox.Show("Logon user throwing " + token + " " +    Marshal.GetLastWin32Error());
}

Thanks for the help!

¿Fue útil?

Solución

This is related to Windows Local Security Policy,

The user should have the 'Log on as a service' user right assigned.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top