How to uninstall a windows service and delete its files without rebooting

后端 未结 10 1895
终归单人心
终归单人心 2021-01-30 16:40

My current project involves deploying an upgraded .exe file that runs as a Windows Service. In order to overwrite the existing .exe with the new version, I currently need to:

相关标签:
10条回答
  • 2021-01-30 17:20

    As noted by StingyJack and mcbala, and in reference to comments made by Mike L, my experience is that on a Windows 2000 machine, when uninstalling / reinstalling .Net services, "installutil /u" does require a reboot, even when the service was previously stopped. "sc /delete", on the other hand, does not require a reboot - it deletes the service right away (as long as it is stopped).

    I have often wondered, actually, whether there is a good reason "installutil /u" requires a reboot... Is "sc /delete" actually doing something wrong / leaving something hanging?

    0 讨论(0)
  • 2021-01-30 17:21

    My batch file to stop and delete service

    @echo off
    title Service Uninstaller
    color 0A
    set blank=
    set service=blank
    :start
    echo.&echo.&echo.
    SET /P service=Enter the name of the service you want to uninstall:  
    
    IF "%service%"=="" (ECHO Nothing is entered
    GoTo :start)
    cls
    echo.&echo.&echo We will delete the service: %service%
    ping -n 5 -w 1 127.0.0.1>nul
    ::net stop %service%
    ping -n 2 -w 1 127.0.0.1>nul
    sc delete %service%
    pause
    :end
    
    0 讨论(0)
  • 2021-01-30 17:23

    Are you not able to stop the service before the update (and restart after the update) using the commands below?

    net stop <service name>
    net start <service name>
    

    Whenever I'm testing/deploying a service I'm able to upload files without reinstalling as long as the service is stopped. I'm not sure if the issue you are having is different.

    0 讨论(0)
  • 2021-01-30 17:23

    (so Windows releases it's hold on the file)

    Instead, do Ctrl+Alt+Del right after the Stop of the service and kill the .exe of the service. Than, you can uninstall the service without rebooting. This happened to me in the past and it solves the part that you need to reboot.

    0 讨论(0)
提交回复
热议问题