2009-07-02 195 views
2

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

但是,我有2个问题。

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

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

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> 

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

希望它有帮助。

+0

您好,我测试了您的脚本文件,并添加了我自己的productcode和msi名称。但是,当我运行它只是快速闪烁,并没有做任何事情。我错过了什么。我用我的脚本编辑了我的代码。谢谢。 – ant2009 2009-07-02 17:32:57

相关问题