The MASM Forum

General => The Laboratory => Topic started by: mabdelouahab on April 29, 2016, 02:36:54 AM

Title: Start service and restart as admin
Post by: mabdelouahab on April 29, 2016, 02:36:54 AM
I'm working on completing work with Sql Server (http://masm32.com/board/index.php?topic=5299.0), In the meantime I've encountered a problem: How can I make sure that customer service works
And how do I restarted if stoped
Also, This requires that the program must running as administrator
I made this program to make sure that it works well in all conditions
I suggested : "Audiosrv" Windows Audio Service; you can work on any other service.
Code: [Select]
ServiceName EQU BSTR$("Audiosrv") ;Just for test: Windows Audio Service
Also you can choose a .Net version
Code: [Select]
; CLR = 2 For .Net 2/2.5/3/3.5
; CLR = 4 For .Net 4/4.5

__ClrVersion EQU 2 ; 4
Title: Re: Start service and restart as admin
Post by: mabdelouahab on April 29, 2016, 06:56:06 AM
If no error occurs, it will be as follows:
The first run:

Quote
The program needs to run As Administrator
Press any key to continue ...

the second run:
Quote

 Audiosrv Service is  Running
 wait for Stop the service
Press any key to continue ...

 Audiosrv Service is Not Running
 wait for running the service
Press any key to continue ...
Title: Re: Start service and restart as admin
Post by: fearless on April 29, 2016, 07:56:16 AM
Could use the win32 service manager functions:

OpenSCManager: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684323%28v=vs.85%29.aspx
OpenService: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684330%28v=vs.85%29.aspx
QueryServiceStatus: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684939%28v=vs.85%29.aspx for SERVER_STATUS (https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996%28v=vs.85%29.aspx)
and NotifyServiceStatusChange https://msdn.microsoft.com/en-us/library/windows/desktop/ms684276%28v=vs.85%29.aspx for when a server stops and you want to try and restart it perhaps?