zoukankan      html  css  js  c++  java
  • Bat脚本自动卸载软件-静默执行

    通过Bat脚本卸载软件,原理是得到某软件的ProductCode,然后通过MsiExec.exe命令卸载软件,下面是卸载一个产品的基本代码示例:

    set ML4.0HF4Name=Product4.0HF4
    set ML4.0HF4ProduceCode=420F1D5E-A797-4FB8-B656-DAC18FAB86FE
    
    ::Product4.0HF4
    echo %ML4.0HF4Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0HF4ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0HF4Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0HF4Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0HF4Name% End %date% %time%>>%logfile%

    以下代码是一个完全的示例,包含所有过程,比较繁琐,有日志功能;删除产品文件夹功能

    @echo off
    
    :: base parameters
    set logfile=C:UnInstallProductLog.txt
    ::set datetime=%date% %time%
    set ProductFolder="C:Program FilesProduct"
    
    
    :: Name and ProductCode
    set ML4.0SP1Name=Product4.0SP1
    set ML4.0SP1ProduceCode=AD66CA3A-BAA3-45E4-B7D9-22BB2B8775D1
    
    set MLDB4.0SP1Name=ProductDababase4.0SP1
    set MLDB4.0SP1ProduceCode=C9823940-D109-43F2-81F7-B76C7B923DE3
    
    
    set ML4.0HF4Name=Product4.0HF4
    set ML4.0HF4ProduceCode=420F1D5E-A797-4FB8-B656-DAC18FAB86FE
    
    set MLDB4.0HF4Name=ProductDababase4.0HF4
    set MLDB4.0HF4ProduceCode=F4410B3A-6AB8-4E63-9716-41B11693A29B
    
    
    set ML4.0HF3Name=Product4.0HF3
    set ML4.0HF3ProduceCode=F943817E-793F-4457-A449-BE4BCEFB5114
    
    set MLDB4.0HF3Name=ProductDababase4.0HF3
    set MLDB4.0HF3ProduceCode=67F3B4E7-998B-4E88-B6DE-E84F18F9A0E2
    
    
    set ML4.0HF2Name=Product4.0HF2
    set ML4.0HF2ProduceCode=4D840F90-B500-4279-9768-A1339E9B75B0
    
    set MLDB4.0HF2Name=ProductDababase4.0HF2
    set MLDB4.0HF2ProduceCode=40632512-8D09-4A09-BF6C-F26EDD87773C
    
    
    set ML4.0HF1Name=Product4.0HF1
    set ML4.0HF1ProduceCode=DE09302B-9B90-4F66-9B2A-13C67A29CCAB
    
    
    set ML4.0Name=Product4.0
    set ML4.0ProduceCode=176C5F1C-8E45-41CD-B42D-562E8D4870C8
    
    set DCMedia4.0Name=DisplayControllerMedia4.0
    set DCMedia4.0ProductCode=F27974D3-A978-4112-9B1F-25D7D425A607
    
    set MLDB4.0Name=ProductDatabase4.0
    set MLDB4.0ProductCode=871760A0-BC0F-4591-9515-A21A12D6DF58
    
    set ARAnimation4.0Name=AspersRouletteAnimations4.0
    set ARAnimation4.0ProductCode=9845E4C0-5639-44F8-849C-B79D2182892C
    
    set BRAnimation4.0Name=BlankRouletteAnimations4.0
    set BRAnimation4.0ProductCode=DE3CC285-FFE5-4A3F-9DFC-6AD8E0F2BDAF
    
    set GCRAnimation4.0Name=GCasinoRouletteAnimations4.0
    set GCRAnimation4.0ProductCode=A2F491B3-23AD-4684-87E4-194C74B8231E
    
    set GRAnimation4.0Name=GrosvenorRouletteAnimations4.0
    set GRAnimation4.0ProductCode=8962F6E6-B982-48CB-81EE-8A1C369A18BE
    
    set FTPServer4.0Name=FTPServer4.0
    set FTPServer4.0ProductCode=750381B9-BC1C-4308-93D9-9BEC409C5733
    
    ::Machine IP Information
    echo Machine IP Information:>>%logfile%
    ipconfig>>%logfile%
    
    :: Start Execute
    echo Uninstall Product Start...%date% %time%>>%logfile%
    
    
    ::Product4.0SP1
    echo %ML4.0SP1Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0SP1ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0SP1Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0SP1Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0SP1Name% End %date% %time%>>%logfile%
    
    ::ProductDababase4.0SP1
    echo %MLDB4.0SP1Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%MLDB4.0SP1ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %MLDB4.0SP1Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %MLDB4.0SP1Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %MLDB4.0SP1Name% End %date% %time%>>%logfile%
    
    
    ::Product4.0HF4
    echo %ML4.0HF4Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0HF4ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0HF4Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0HF4Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0HF4Name% End %date% %time%>>%logfile%
    
    ::ProductDababase4.0HF4
    echo %MLDB4.0HF4Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%MLDB4.0HF4ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %MLDB4.0HF4Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %MLDB4.0HF4Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %MLDB4.0HF4Name% End %date% %time%>>%logfile%
    
    
    ::Product4.0HF3
    echo %ML4.0HF3Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0HF3ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0HF3Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0HF3Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0HF3Name% End %date% %time%>>%logfile%
    
    ::ProductDababase4.0HF3
    echo %MLDB4.0HF3Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%MLDB4.0HF3ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %MLDB4.0HF3Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %MLDB4.0HF3Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %MLDB4.0HF3Name% End %date% %time%>>%logfile%
    
    
    ::Product4.0HF2
    echo %ML4.0HF2Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0HF2ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0HF2Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0HF2Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0HF2Name% End %date% %time%>>%logfile%
    
    ::ProductDababase4.0HF2
    echo %MLDB4.0HF2Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%MLDB4.0HF2ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %MLDB4.0HF2Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %MLDB4.0HF2Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %MLDB4.0HF2Name% End %date% %time%>>%logfile%
    
    
    ::Product4.0HF1
    echo %ML4.0HF1Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0HF1ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0HF1Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0HF1Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0HF1Name% End %date% %time%>>%logfile%
    
    
    ::Product4.0
    echo %ML4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ML4.0ProduceCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ML4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ML4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ML4.0Name% End %date% %time%>>%logfile%
    
    ::DisplayControllerMedia4.0
    echo %DCMedia4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%DCMedia4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %DCMedia4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %DCMedia4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %DCMedia4.0Name% End %date% %time%>>%logfile%
    
    ::ProductDatabase4.0
    echo %MLDB4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%MLDB4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %MLDB4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %MLDB4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %MLDB4.0Name% End %date% %time%>>%logfile%
    
    ::AspersRouletteAnimations4.0
    echo %ARAnimation4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%ARAnimation4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %ARAnimation4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %ARAnimation4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %ARAnimation4.0Name% End %date% %time%>>%logfile%
    
    ::BlankRouletteAnimations4.0
    echo %BRAnimation4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%BRAnimation4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %BRAnimation4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %BRAnimation4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %BRAnimation4.0Name% End %date% %time%>>%logfile%
    
    ::GCasinoRouletteAnimations4.0
    echo %GCRAnimation4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%GCRAnimation4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %GCRAnimation4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %GCRAnimation4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %GCRAnimation4.0Name% End %date% %time%>>%logfile%
    
    ::GrosvenorRouletteAnimations4.0
    echo %GRAnimation4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%GRAnimation4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %GRAnimation4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %GRAnimation4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %GRAnimation4.0Name% End %date% %time%>>%logfile%
    
    ::FTPServer4.0
    echo %FTPServer4.0Name% Start...%date% %time%>>%logfile%
    MsiExec.exe /X{%FTPServer4.0ProductCode%} /qn /Lwme+ %logfile%
    IF %ERRORLEVEL% EQU 0 echo Uninstall %FTPServer4.0Name% Successfull
    IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 1605 echo Uninstall %FTPServer4.0Name% Failed, ERRORLEVEL:%ERRORLEVEL%.
    echo ERRORLEVEL:%ERRORLEVEL%>>%logfile%
    echo %FTPServer4.0Name% End %date% %time%>>%logfile%
    
    
    :: End Execute
    echo Uninstall Product End%date% %time%>>%logfile%
    
    ::Delete ProductFolder
    rd %ProductFolder% /s /q || rem
    IF %ERRORLEVEL% EQU 0 echo Delete %ProductFolder% Folder Successfull
    IF %ERRORLEVEL% NEQ 0 echo Delete %ProductFolder% Folder Failed, ERRORLEVEL:%ERRORLEVEL%.
    
    pause
    View Code
  • 相关阅读:
    分分钟搞定Python之排序与列表
    分分钟搞定Python之排序与列表
    联系我
    联系我
    联系我
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1
    联系表单 1
  • 原文地址:https://www.cnblogs.com/zhengshuangliang/p/4238008.html
Copyright © 2011-2022 走看看