• window 服务的安装和卸载


    安装批处理文件:

    @echo off
    echo 服务路径
    set filename=E:ApplicationSubApplicationKSCGQuzationServiceKSCGQuzationServiceinDebugKSCGQuzationService.exe
    echo 服务名称(与程序中设定的一样)
    set servicename=KSCGQuzationService.exe
    pause
    echo ============================操作日志==================================== >InstallService.log
    if exist "%SystemRoot%Microsoft.NETFrameworkv4.0.30319" goto netOld
    :DispError
    echo 您的机器上没有安装 .net Framework 4.0,安装即将终止
    echo 您的机器上没有安装 .net Framework 4.0,安装即将终止 >>InstallService.log
    goto LastEnd
    :netOld
    cd %SystemRoot%Microsoft.NETFrameworkv4.0.30319
    echo 您的机器上安装了相应的.net Framework 4.0,可以安装本服务.
    echo 您的机器上安装了相应的.net Framework 4.0,可以安装本服务 >>InstallService.log
    echo off
    echo 清理原有服务项. . .
    %SystemRoot%Microsoft.NETFrameworkv4.0.30319installutil /U %filename% >> InstallService.log
    echo 清理完毕
    echo.
    echo *********************
    echo 安装服务
    %SystemRoot%Microsoft.NETFrameworkv4.0.30319installutil %filename% >> InstallService.log
    echo 启动服务
    net start %servicename% >> InstallService.log
    echo *********************
    echo ======================================================================= >>InstallService.log
    type InstallService.log
    echo.
    echo 操作结束,可以查看日志文件InstallService.log 中具体的操作结果。
    :LastEnd
    pause
    rem exit

    将上面的代码拷入记事本,保存为.bat文件,已“管理员身份运行”即可。

    卸载服务批处理文件:

    echo off
    set filename=E:ApplicationSubApplicationKSCGQuzationServiceKSCGQuzationServiceinDebugKSCGQuzationService.exe
    set servicename=YookeyQuzation
    echo ============================操作日志==================================== >UnInstallService.log
    if exist "%SystemRoot%Microsoft.NETFrameworkv4.0.30319" goto netOld
    :DispError
    echo 您的机器上没有安装.net FrameWork 4.0,卸载即将终止
    echo 您的机器上没有安装.net FrameWork 4.0,卸载即将终止 >>UnInstallService.log
    pause
    goto LastEnd
    :netOld
    echo 即将卸载本服务…
    echo off
    pause
    echo *********************
    echo 停止服务
    net stop %servicename% >>UnInstallService.log
    cd %SystemRoot%Microsoft.NETFrameworkv4.0.30319
    %SystemRoot%Microsoft.NETFrameworkv4.0.30319installutil /uninstall %filename% >>UnInstallService.log
    echo 卸载服务
    echo ======================================================================= >>UnInstallService.log
    echo *********************
    type UnInstallService.log
    echo.
    echo 操作结束,可以查看日志文件UnInstallService.log中具体的操作结果。
    :LastEnd
    pause
    rem exit

    和安装服务的方法一样,将上面的代码复制到文本文件中保存为.bat格式的文件,已“管理员身份运行”。

    特别需要注意的是上面的filename路径和servicename 服务名称。设置不对将会安装和卸载失败。

  • 相关阅读:
    POJ3320 Jessica's Reading Problem
    POJ3320 Jessica's Reading Problem
    CodeForces 813B The Golden Age
    CodeForces 813B The Golden Age
    An impassioned circulation of affection CodeForces
    An impassioned circulation of affection CodeForces
    Codeforces Round #444 (Div. 2) B. Cubes for Masha
    2013=7=21 进制转换
    2013=7=15
    2013=7=14
  • 原文地址:https://www.cnblogs.com/epic0583/p/4572209.html
Copyright © 2020-2023  润新知