;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Service Control Program
for
beeper driver
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; I N C L U D E F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
include \RadASM\masm32\Macros\Strings.mac
includelib debug.lib
include debug.inc
; ----------------------debug-------------------------------
; PrintError
; PrintText<
"debug message!"
>
; PrintString<driver>
; PrintStringByAddr<offset driver>
; PrintDword<hSCManager,driver>
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
start proc
local
hSCManager:HANDLE
local
hService:HANDLE
local
acDriverPath[MAX_PATH]:CHAR
LOCAL bRet:BOOL
LOCAL SvrSta
invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE
mov hSCManager, eax
PrintDec hSCManager
.
if
hSCManager != NULL
invoke GetFullPathName, $CTA0(
"beeper.sys"
),sizeof acDriverPath,addr acDriverPath,NULL
PrintString acDriverPath
invoke CreateService, hSCManager, $CTA0(
"beeper"
), $CTA0(
"Beeper"
), \
SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \
SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL
mov hService, eax
PrintDec hService
.
if
hService==NULL
PrintError
invoke GetLastError
; 服务创建失败,是由于服务已经创立过
.
if
eax==ERROR_IO_PENDING || eax==ERROR_SERVICE_EXISTS || eax==ERROR_SERVICE_MARKED_FOR_DELETE
invoke OpenService ,hSCManager,$CTA0(
"beeper"
), SERVICE_ALL_ACCESS
mov hService, eax
push eax
;如果打开服务也失败,则意味错误
.
if
eax==NULL
pop eax
PrintError
jmp
exit
.endif
pop eax
;服务创建失败,是由于服务已经标记删除
.
if
eax==ERROR_SERVICE_MARKED_FOR_DELETE
invoke ControlService,hService,SERVICE_CONTROL_STOP, addr SvrSta
invoke CloseServiceHandle,hService
;再次创建
invoke CreateService, hSCManager, $CTA0(
"beeper"
), $CTA0(
"beeper"
), \
SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \
SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL
;如果再次创建再失败,则意味着错误
.
if
eax==NULL
PrintError
mov bRet,FALSE
jmp
exit
.endif
.endif
;由于其他原因创建服务失败
.
else
PrintText
"注册驱动时出错,出错信息如下:"
PrintError
mov bRet,FALSE
jmp
exit
.endif
.endif
invoke StartService, hService, 0, NULL
invoke DeleteService, hService
.
else
invoke MessageBox, NULL, $CTA0(
"打开服务管理器出错."
), \
NULL, MB_ICONSTOP
PrintText
"打开服务管理器出错"
PrintError
.endif
exit
:
.
if
hService
invoke CloseServiceHandle ,hService ; 服务句柄
.endif
.
if
hSCManager
invoke CloseServiceHandle ,hSCManager; SCM句柄
.endif
invoke ExitProcess, 0
start endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end start