bat文件卸载已安装的应用程序

时间:2009-07-02 10:49:32

标签: batch-file

我正在使用以下bat文件在用户计算机上安装我的应用程序。但是,客户端希望能够在安装应用程序时卸载应用程序,然后安装新版本的应用程序。

但是,我有两个问题。

1)如何检测应用程序是否已安装?

2)如果已安装,我该如何卸载它?

该应用程序是C#2005。

@ECHO OFF
:: Copy the configuration file
copy config.xml "%AppData%\DataLinks.xml"

:: Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0
SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.
ECHO.This is required by the setup program for CAT Dialer
ECHO.
ECHO.The Microsoft(c) .NET Framework 2.0 will now be installed on you system.
ECHO.After completion setup will continue to install CAT Dialer on your system.
ECHO.
:: Install the .Net framework and then run setup to install the CAT Dialerr 
PAUSE
ECHO Installing... this could take several minutes...Please wait....
START /WAIT NetFx20SP2_x86.exe
:: If the user cancels the installation of the framework exit batch file
IF errorlevel 1 GOTO EOF
Start CATSoftphone.exe
ECHO ON
EXIT

:: .Net framework has been skipped contine to install the dialer.
:INSTALL_DIALER
ECHO *** Skiped Dotnet Framework 2.0.50727 ***
ECHO Installing... Please wait...
START CATSoftphone.exe
ECHO ON
EXIT

编辑==============================

<job id="ReInstall">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {2E92DD55-37E9-4D6C-B55B-DAFD9DF583E2}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
    oExec = WshShell.Run("InstallUninstallBat.msi")
End If
</script>
</job>

2 个答案:

答案 0 :(得分:2)

您可能最好使用流行的(免费)NSIS安装程序平台,而不是使用批处理脚本。您可以使用它完成所有相同的操作,并且构建卸载程序要容易得多。

答案 1 :(得分:1)

在我的公司,同样的请求与VB脚本相对应,如:

<job id="ReInstallblabla">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {3D96B234-EB0C-4AC3-89EC-E5CAB9AEC432}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
    oExec = WshShell.Run("blabla_setup.msi")
End If
</script>
</job>

如果您能够为您的应用程序创建一个部署项目,它将有一个ProductCode,您可以将其作为参数传递给msiexec。返回值0表示卸载成功,1605表示没有找到给定ProductCode的安装。

希望它有所帮助。

相关问题