2009-08-06 165 views
0

我为我的应用程序创建了一个VS安装项目。它将应用程序安装到用户定义的位置并在开始菜单中创建几个快捷方式。它还在控制面板/添加或删除程序中创建可用于卸载应用程序的条目。.NET安装项目和卸载程序

我想知道是否有办法创建一个可以卸载我的应用程序的开始菜单条目(由安装程序创建的其他条目旁边)。

到目前为止,我找到了一个解决方案,但使用起来非常痛苦:我创建了uninstall.bat文件,我在我的应用程序文件夹中进行了部署,并且正在为此文件添加快捷方式。在*.bat的内容是这样的:

@echo off 
msiexec /x {0B02B2AB-12C6-4548-BF90-F754372B0D36} 

我不喜欢这个解决方案是什么,每次我更新我的应用程序的产品代码的时间(我做的,每当我更新我的应用程序版本VS建议)我必须在构建安装项目并输入正确的新产品代码之前手动编辑此文件。

有没有人知道更简单的方式添加卸载程序的应用程序?

+0

http://robmensching.com/blog/posts/2007/4/27/How-to-create-an-uninstall-shortcut-and-pass-all- – 2010-08-20 02:24:25

回答

1

您可以编辑.bat文件来接受参数。

@echo off 
msiexec /x %1 

在设置项目中定义快捷方式的地方,添加[ProductCode]属性作为参数。

+0

我猜。但是有没有更优雅的方式呢?我很乐意删除整个'bat'文件并完全创建卸载程序来完成安装项目。 – RaYell 2009-08-06 14:42:19

+2

在这种情况下,我会建议您使用WiX代替。 – 2009-08-06 14:52:09

1

我有这个确切的问题。

我所做的是这样的:

  • 提供uninstall.bat文件。无条件安装此文件
  • 在安装程序中提供自定义操作,即重写 uninstall.bat文件,并插入正确的产品代码。

这里运行的自定义操作的脚本。它重写uninstall.bat文件,然后删除它自己。

// CreateUninstaller.js 
// 
// Runs on installation, to create an uninstaller 
// .cmd file in the application folder. This makes it 
// easy to uninstall. 
// 
// Mon, 31 Aug 2009 05:13 
// 

var fso, ts; 
var ForWriting= 2; 
fso = new ActiveXObject("Scripting.FileSystemObject"); 

var parameters = Session.Property("CustomActionData").split("|"); 
var targetDir = parameters[0]; 
var productCode = parameters[1]; 

ts = fso.OpenTextFile(targetDir + "uninstall.cmd", ForWriting, true); 


ts.WriteLine("@echo off"); 
ts.WriteLine("goto START"); 
ts.WriteLine("======================================================="); 
ts.WriteLine(" Uninstall.cmd"); 
ts.WriteBlankLines(1); 
ts.WriteLine(" This is part of MyProduct."); 
ts.WriteBlankLines(1); 
ts.WriteLine(" Run this to uninstall MyProduct"); 
ts.WriteBlankLines(1); 
ts.WriteLine("======================================================="); 
ts.WriteBlankLines(1); 
ts.WriteLine(":START"); 
ts.WriteLine("@REM The uuid is the 'ProductCode' in the Visual Studio setup project"); 
ts.WriteLine("%windir%\\system32\\msiexec /x " + productCode); 
ts.WriteBlankLines(1); 
ts.Close(); 


// all done - try to delete myself. 
try 
{ 
    var scriptName = targetDir + "createUninstaller.js"; 
    if (fso.FileExists(scriptName)) 
    { 
     fso.DeleteFile(scriptName); 
    } 
} 
catch (e2) 
{ 
} 

我想我可以用WiX做到这一点,但我不想去了解它。

相关问题