找到了方法。思路很简单,主要有以下几点。
一是FailureActions:这个是其实就是启动失败后的操作,经过测试,也是服务进程结束(失败)后的操作,这个是关键,没有这个操作则结束进程后不会再自动启动服务。我下面的FailureActions无论你怎么结束都无法结束,因为会自动生成。
二是使用setacl设置服务的注册表权限,禁止被删除,这样你使用服务管理器的时候无法停止进程。
三是使用setacl设置服务的操作权限为只读,这样用户就不能停止服务了。
代码如下:具体可以参考我的BLOG:http://xbdsoft.kmip.net/article/gsoft/52.htm
SC CREATE "ekrn" TYPE= INTERACT TYPE= OWN START= AUTO BINPATH= "%CD%\ekrn.exe" DISPLAYNAME= "Eset Service"
REM SC failure ekrn reset= 60 actions= restart/60/restart/60/restart/60
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ekrn" /v "FailureActions" /t REG_BINARY /d "3C000000000000000000000001000000000000000100000000000000" /f
NET START "Eset Service">NUL
set op=-ot reg -actn ace -ace "n:everyone;p:read;m:grant;w:dacl" -actn setprot -op "dacl:p_nc"
IF NOT "%WINDIR:~-2%"=="PE" setacl -on "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ekrn" %op%
set svr=-ot srv -actn ace -ace "n:Everyone;m:grant;p:read;i:sc"
Last edited by HUNRYBECKY on 2009-3-18 at 06:02 ]
Found the method. The idea is very simple, mainly the following points.
First, FailureActions: this is actually the operation after startup failure. After testing, it is also the operation after the service process ends (fails). This is the key. Without this operation, the process will not automatically restart the service after ending. The following FailureActions of mine cannot be ended no matter how you end it because it will be automatically generated.
Second, use setacl to set the registry permissions of the service to prohibit deletion, so that you cannot stop the process when using the service manager.
Third, use setacl to set the operation permissions of the service to read-only, so that users cannot stop the service.
The code is as follows: For details, you can refer to my BLOG: http://xbdsoft.kmip.net/article/gsoft/52.htm
SC CREATE "ekrn" TYPE= INTERACT TYPE= OWN START= AUTO BINPATH= "%CD%\ekrn.exe" DISPLAYNAME= "Eset Service"
REM SC failure ekrn reset= 60 actions= restart/60/restart/60/restart/60
REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ekrn" /v "FailureActions" /t REG_BINARY /d "3C000000000000000000000001000000000000000100000000000000" /f
NET START "Eset Service">NUL
set op=-ot reg -actn ace -ace "n:everyone;p:read;m:grant;w:dacl" -actn setprot -op "dacl:p_nc"
IF NOT "%WINDIR:~-2%"=="PE" setacl -on "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ekrn" %op%
set svr=-ot srv -actn ace -ace "n:Everyone;m:grant;p:read;i:sc"
Last edited by HUNRYBECKY on 2009-3-18 at 06:02 ]