flat assembler
Message board for the users of flat assembler.
Index
> Windows > Windows service example? |
Author |
|
bzdashek 20 Dec 2012, 10:04
Good day, everyone.
I used search, but my search didn't get me anywhere. Google points to .NET examples of service creation. So, does anyone have a simple example of windows service? What functions are mandatory for it that should be exported? Anything would do - C/C++ or ASM. Here are some examples on .NET, in case someone would need those: Example 1 Example 2 |
|||
20 Dec 2012, 10:04 |
|
Lummis 20 Dec 2012, 12:07
Hi. No one answered yet, but I'll follow with a question instead! lol
What is a Windows Service? I looked a bit, but this stuff doesn't show & tell what the heck they are really talking about... http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase AND are there 'general solutions' to porting to the Windows 'calls'? THX. |
|||
20 Dec 2012, 12:07 |
|
marcinzabrze12 20 Dec 2012, 19:24
service:
Code: format pe console entry main include 'win32ax.inc' include 'n\codehelp.inc' include 'n\SERVICE.INC' SERVICE_CONTROL_SHUTDOWN = 00000005h SERVICE_CONTROL_CREATE_OUT_FILE = 00000096h section '.idata' import data readable library msvcrt, 'msvcrt.dll', kernel32, 'kernel32.dll',\ user32, 'user32.dll', advapi32, 'advapi32.dll',\ shell32, 'shell32.dll' include 'api\msvcrt.inc' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\advapi32.inc' include 'api\shell32.inc' section '.data' data readable writeable serviceName db 'mainservice', 0 serviceStatus SERVICE_STATUS serviceStatusHandle dd ? ; ------------------------------------------------------------- pathBuffer db MAX_PATH dup 0 newthreadID dd ? newthreadHandle dd ? outFileName db 'outfile.asm', 0 outFileHandle dd ? ; ------------------------------------------------------------- ; ========================================================================== section '.code' code readable executable ; ========================================================================== proc SvcHandlerEx dwControl, dwEventType, lpEventData, lpContext pushfd mov eax, [dwControl] cmp eax, SERVICE_CONTROL_PAUSE je .service_pause cmp eax, SERVICE_CONTROL_CONTINUE je .service_continue cmp eax, SERVICE_CONTROL_STOP je .service_stop cmp eax, SERVICE_CONTROL_SHUTDOWN je .service_stop popfd ret .service_pause: mov dword [serviceStatus.dwCurrentState], SERVICE_PAUSED jmp .finish .service_continue: mov dword [serviceStatus.dwCurrentState], SERVICE_RUNNING jmp .finish .service_stop: mov dword [serviceStatus.dwCurrentState], SERVICE_STOPPED .finish: invoke SetServiceStatus, [serviceStatusHandle], serviceStatus mov eax, NO_ERROR popfd ret endp proc ServiceMain argc:DWORD, argv:DWORD pushfd mov dword [serviceStatus.dwServiceType], SERVICE_WIN32_OWN_PROCESS mov dword [serviceStatus.dwCurrentState], SERVICE_RUNNING mov dword [serviceStatus.dwControlsAccepted], SERVICE_ACCEPT_PAUSE_CONTINUE or SERVICE_ACCEPT_STOP or SERVICE_ACCEPT_SHUTDOWN mov dword [serviceStatus.dwWin32ExitCode], NO_ERROR mov dword [serviceStatus.dwServiceSpecificExitCode], 0 mov dword [serviceStatus.dwCheckPoint], 0 mov dword [serviceStatus.dwWaitHint], 0 invoke RegisterServiceCtrlHandlerExA, serviceName, SvcHandlerEx, NULL mov [serviceStatusHandle], eax invoke SetServiceStatus, eax, serviceStatus popfd ret endp ; ================================================================================================================================ ; MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN ; ================================================================================================================================ proc main argc:DWORD, lpszArgv:DWORD pushfd locals svc SERVICE_TABLE_ENTRY dd NULL dd NULL endl mov [svc.lpServiceName], serviceName mov [svc.lpServiceProc], ServiceMain lea eax, [svc] invoke StartServiceCtrlDispatcher, eax xor eax, eax popfd ret endp ; ================================================================================================================================ ; MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN ; ================================================================================================================================ section '.reloc' fixups data discardable instalator: Code: entry start include 'win32ax.inc' include 'n\codehelp.inc' include 'n\SERVICE.INC' section '.idata' import data readable library kernel32, 'kernel32.dll', user32, 'user32.dll', advapi32, 'advapi32.dll' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\advapi32.inc' section '.data' data readable writeable hinstance dd ? serviceName db 'MAINSERVICE', 0 serviceType dd SERVICE_WIN32_OWN_PROCESS serviceBinaryPath db 'C:\Users\neptun\Desktop\SVC\mainservice.exe', 0 serviceDescription db 'USLUGA TESTOWA: <WAWRZYNIAKMARCINCODE@GMAIL.COM>', 0 ; ------------------------------------------------------------------------------- hnService dd ? idesc SERVICE_DESCRIPTION ; ------------------------------------------------------------------------------- ; ========================================================================== section '.code' code readable writeable executable ; ========================================================================== start: ; --------------------------------------------------------------------------------------- stdcall ServiceInstall, serviceName, serviceName, serviceBinaryPath,\ SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE test eax, eax jnz @f SHOWERROR 'mainservice install error' EXITPROCESS @@: MSG 'SUCCESS - USLUGA ZOSTALA ZAINSTALOWANA I URUCHOMIONA', 'mainservice install' ; --------------------------------------------------------------------------------------- stdcall ServiceSetDescription, serviceName, serviceDescription .if eax = FALSE SHOWERROR 'ServiceSetDescription() Error:' EXITPROCESS .endif MSG 'Ustanowiono opis uslugi.' EXITPROCESS uninstall it: Code: format pe gui 4.0 entry start include 'win32ax.inc' include 'n\codehelp.inc' include 'n\PRIVILEGES.INC' include 'n\SERVICE.INC' section '.idata' import data readable library kernel32, 'kernel32.dll', user32, 'user32.dll', advapi32, 'advapi32.dll' include 'api\kernel32.inc' include 'api\user32.inc' include 'api\advapi32.inc' section '.data' data readable writeable hinstance dd ? serviceName db 'MAINSERVICE', 0 serviceType dd SERVICE_WIN32_OWN_PROCESS ; ========================================================================== section '.code' code readable writeable executable ; ========================================================================== start: stdcall ServiceUninstall, serviceName .if eax = 0 SHOWERROR 'ServiceUninstall() ERROR:' EXITPROCESS .endif MSG 'successik' EXITPROCESS the all uses main procedures like ServiceInstall, ServiceUninstall ... from this file: https://docs.google.com/open?id=0Bzkm-XARAFtnX044NlpMa2FSdU0 |
|||
20 Dec 2012, 19:24 |
|
typedef 20 Dec 2012, 22:04
Here. I quickly wrote this for you. Took me about an hour or so.
All it does is prints string using OutputDebugString
|
|||||||||||
20 Dec 2012, 22:04 |
|
bzdashek 21 Dec 2012, 05:07
typedef wrote: Here. I quickly wrote this for you. Took me about an hour or so. Thanks a lot, typedef. Yay, it's full of commentaries! Thanks, everyone, I'll proceed with creating my service. |
|||
21 Dec 2012, 05:07 |
|
Lummis 23 Dec 2012, 14:09
I also found stuff in fasm's source and include files, ... + reading the win32 help...
Thx guys. |
|||
23 Dec 2012, 14:09 |
|
bzdashek 23 Dec 2012, 15:02
Lummis wrote: I also found stuff in fasm's source and include files, ... + reading the win32 help... You might want to take a look at this thread, if you haven't already done so: http://board.flatassembler.net/topic.php?t=13931 It contains extended includes by madmatt, containing all thinkable and unthinkable structures you might ever need. |
|||
23 Dec 2012, 15:02 |
|
upsurt 16 Apr 2014, 14:22
that's very helpful! thank you alot!
how can I add a timer (1 second) to the windows service, to performe an action every second? |
|||
16 Apr 2014, 14:22 |
|
edfed 16 Apr 2014, 22:02
Google->MSDN->SetTimer ????
|
|||
16 Apr 2014, 22:02 |
|
typedef 17 Apr 2014, 23:22
Don't use timers. If you have to use timers use threaded ones otherwise just use a thread.
|
|||
17 Apr 2014, 23:22 |
|
revolution 17 Apr 2014, 23:25
typedef wrote: Don't use timers. If you have to use timers use threaded ones otherwise just use a thread. |
|||
17 Apr 2014, 23:25 |
|
edfed 18 Apr 2014, 08:09
timers in windows seems to still be threads.... means the SetTimer function (if you go in msdn to be sure) will run independentlly from the setter application.
to be really sure, and without reading the msdn, you can also try it, the simple way to do it is to loop continuouslly you main program on an intense computation, and do the same with the timer. if the main runs correctlly without delay, and the timer too, then, they run separatelly.... something like that. |
|||
18 Apr 2014, 08:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.