uninstall service in condition

Dani_S 2,726 Reputation points
2023-05-22T07:03:01.61+00:00

Hi,

I run in MAUI batch file and i want to uninstall service.

First i want to check if it running if yes to stop it and only after to uninstall it using this code.

How i do it ?

This the code for uninstall

@ECHO OFF

echo stop GS Automation Service 

echo ---------------------------------------------------

sc.exe stop "GS Automation Service" 

pause

echo Done.

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,166 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Dani_S 2,726 Reputation points
    2023-06-05T07:55:38.9+00:00
    @ECHO OFF
    
    for /F "tokens=3 delims=: " %%H in ('sc query "GS Automation Service" ^| findstr "        STATE"') do (
      if /I "%%H" EQU "RUNNING" (
       echo Stop GS Automation Service......
       sc.exe stop "GS Automation Service"
      )
    )
    echo Delete GS Automation Service......
    echo ---------------------------------------------------
    sc.exe delete "GS Automation Service"
    echo ---------------------------------------------------
    
    
    0 comments No comments

  2. Dani_S 2,726 Reputation points
    2023-06-11T13:20:47.1133333+00:00

    See answer above

    0 comments No comments