Hi all:
I read an article from
http://www.c-sharpcorner.com/Code/20...mmatically.asp
about how to install a windows service programmaticall y.
Based ont the code sample, it provides the feature to install service
under LocalSystem account.
What I need is to install service under some other certian account. By
further studying the code, and MSDN
(http://msdn.microsoft.com/library/de...-us/dllproc/ba
se/createservice.a sp) ,
public static extern IntPtr CreateService(I ntPtr SC_HANDLE,strin g
lpSvcName,strin g lpDisplayName,
int dwDesiredAccess ,int dwServiceType,i nt dwStartType,int
dwErrorControl, string lpPathName,
string lpLoadOrderGrou p,int lpdwTagId,strin g lpDependencies, string
lpServiceStartN ame,string lpPassword);
is the core API to create a service. And the last two parameters should be
name and password of account under wihcih service should run. But when I
tried to pass values to these two parameters bu calling:
sv_handle = CreateService(s c_handle, serviceName, serviceDisplayN ame,
SERVICE_ALL_ACC ESS, SERVICE_WIN32_O WN_PROCESS,
SERVICE_AUTO_ST ART, SERVICE_ERROR_N ORMAL,
servicePath, null, 0, null, _UserName, _Password);
This piece of code is just a bit different from original, but sv_handle
return is 0, which means failure.
Anybody has idea how to install a service under some certain account?
Thanks for any suggestion.
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
I read an article from
http://www.c-sharpcorner.com/Code/20...mmatically.asp
about how to install a windows service programmaticall y.
Based ont the code sample, it provides the feature to install service
under LocalSystem account.
What I need is to install service under some other certian account. By
further studying the code, and MSDN
(http://msdn.microsoft.com/library/de...-us/dllproc/ba
se/createservice.a sp) ,
public static extern IntPtr CreateService(I ntPtr SC_HANDLE,strin g
lpSvcName,strin g lpDisplayName,
int dwDesiredAccess ,int dwServiceType,i nt dwStartType,int
dwErrorControl, string lpPathName,
string lpLoadOrderGrou p,int lpdwTagId,strin g lpDependencies, string
lpServiceStartN ame,string lpPassword);
is the core API to create a service. And the last two parameters should be
name and password of account under wihcih service should run. But when I
tried to pass values to these two parameters bu calling:
sv_handle = CreateService(s c_handle, serviceName, serviceDisplayN ame,
SERVICE_ALL_ACC ESS, SERVICE_WIN32_O WN_PROCESS,
SERVICE_AUTO_ST ART, SERVICE_ERROR_N ORMAL,
servicePath, null, 0, null, _UserName, _Password);
This piece of code is just a bit different from original, but sv_handle
return is 0, which means failure.
Anybody has idea how to install a service under some certain account?
Thanks for any suggestion.
--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Comment