Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install a service under a different account than the LocalSystem account using Win32 API?

How can I install a service under a different account than the LocalSystem account using Win32 API?

I am using the following code to install the service. I want to install this service under a different account. The last two parameters take username and password but when I give so it throws an error. Is there any specific way of giving username and password here?

IntPtr sv_handle = CreateService(sc_handle, svcName, svcDispName,
                     SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                     SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                     svcPath, null, 0, null, null, null);
like image 384
taher chhabrawala Avatar asked Jan 26 '26 15:01

taher chhabrawala


1 Answers

What format are you using for lpServiceStartName?

It needs to be machinename\\username (or .\\username) if the user name is local or part of a workgroup otherwise it should be domainname\\username.

like image 101
Alex K. Avatar answered Jan 29 '26 06:01

Alex K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!