c++ - Unable to stop a windows service with net stop command -
i have created windows service running fine doing following.
sc_handle hservice = ::createservice(*m_serviceconfig, // scm database name.c_str(), // name of service displayname.c_str(), // service name display service_all_access, // desired access service_win32_own_process | service_interactive_process, // service type (interactive debug) service_auto_start, // start type service_error_normal, // error control type path.c_str(), // path service's binary nullptr, // no load ordering group nullptr, // no tag identifier dependencies, // dependencies nullptr, // localsystem account nullptr); // no password
as can see specified access service_all_access
, online constant states have access pause continue , stop service,
however when run command net stop <service-name>
following ouput
the requested pause continue or stop not valid service
my question is there wrong way im creating service?
service control handler function
dword winapi servicecontrolhandler(dword dwcontrol, dword dweventtype, lpvoid /*lpeventdata*/, lpvoid /*lpcontext*/) { // handle requested control code. switch (dwcontrol) { case service_control_stop: tvlog_info(l"service_control_stop"); { messageboxa(null, "please stop service", "uninstall service error!", mb_ok | mb_iconerror); }
the access rights specify in dwdesiredaccess
parameter of createservice()
have no effect on net stop
command. access rights apply returned sc_handle
, effect how handle interacts subsequent api calls.
the error seeing being caused calls setservicestatus()
not including service_accept_stop
flag in service_status::dwcontrolsaccepted
field.
dwcontrolsaccepted
control codes service accepts , processes in handler function (seehandler
,handlerex
). user interface process can control service specifying control command incontrolservice
orcontrolserviceex
function. default, services accept service_control_interrogate value. accept service_control_deviceevent value, service must register receive device events usingregisterdevicenotification
function.the following control codes.
...
service_accept_stop
0x00000001the service can stopped.
this control code allows service receive service_control_stop notifications.
Comments
Post a Comment