flat assembler
Message board for the users of flat assembler.

Index > Windows > How do I write a service for Windows?

Author
Thread Post new topic Reply to topic
Core i7



Joined: 14 Nov 2024
Posts: 149
Location: Socket on motherboard
Core i7 09 Feb 2026, 12:57
Hello everyone!
I need to write a service for Windows, but I don't know the logic behind it.
Does anyone have a skeleton of a FASM application that I could modify to suit my needs? I think I've figured out the list of API functions, but I'm still unclear on what format to specify in the "format pe64 xxx" line and how to set up a communication channel between the service and my application for data exchange. Thanks in advance for any information.
Post 09 Feb 2026, 12:57
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20874
Location: In your JS exploiting you and your system
revolution 09 Feb 2026, 13:27
The format for .sys files is native.
Code:
format pe64 native

ret    
Post 09 Feb 2026, 13:27
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 149
Location: Socket on motherboard
Core i7 09 Feb 2026, 14:22
revolution, apparently, I didn't explain the problem well. Basically, the scheme is this:
I have a user-mode application and a service to which I want to send commands using the ServiceControl() function. The service returns information to me either through the Clipboard or through Pipes. This is my personal service, which I create with the "SERVICE_WIN32_OWN_PROCESS = 0x10" flag, and immediately delete it when finished. If you run the "ProcessHacker" software, you'll see that all services with the "WIN32_OWN_PROCESS" flag have the *.exe extension, not *.sys. Therefore, I also need to create an EXE, but I'm not sure what format to specify in the "gui\console\native" code header. I suspect I need a GUI. Sorry for my English - this is a translator.


Description:
Filesize: 19.49 KB
Viewed: 265 Time(s)

ph.png


Post 09 Feb 2026, 14:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20874
Location: In your JS exploiting you and your system
revolution 09 Feb 2026, 14:29
For .exe files that don't want a console attached use GUI.
Post 09 Feb 2026, 14:29
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 149
Location: Socket on motherboard
Core i7 10 Feb 2026, 02:23
I looked at the PE-header of one of the services in the system32 folder,
and rightly so—it turns out a GUI format is needed.

Here's a link with a description of all the services' functions:
https://learn.microsoft.com/en-us/windows/win32/services/service-functions
Post 10 Feb 2026, 02:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20874
Location: In your JS exploiting you and your system
revolution 10 Feb 2026, 03:17
A Windows .exe GUI format just tells the loader not to attach a console and redirect stdin, stdout and stderr to the console. Other than that the behaviour is the same as for CONSOLE format.
Post 10 Feb 2026, 03:17
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 149
Location: Socket on motherboard
Core i7 10 Feb 2026, 03:34
That's true, but if you specify CONSOLE for the service, a console window will probably appear on the screen. Although this isn't certain, since starting with Windows 7, all services run in a private session(0), and I don't know whether the service console is passed to the user session(1). However, the GUI format definitely won't show any extra windows, unless you describe the window itself in the resources section.
Post 10 Feb 2026, 03:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20874
Location: In your JS exploiting you and your system
revolution 10 Feb 2026, 04:59
IIRC background services can't open windows in the user's session, there isn't a base desktop for them to paint onto. Since a console is just another window then the console won't appear anywhere.

Can a console .exe successfully run as a service? Maybe the loader will detect that the console window failed to initialise and abort the load? One way to find out is to try it.
Post 10 Feb 2026, 04:59
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 149
Location: Socket on motherboard
Core i7 10 Feb 2026, 05:38
revolution wrote:
IIRC background services can't open windows in the user's session

The service from session(0) can send a window to the user session(1,2,N) via WTSSendMessage(), but I think this is a useless function, since it is better to use IPC mechanisms for exchanging information.
Post 10 Feb 2026, 05:38
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.