0

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

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

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

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

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

有谁知道将卸载程序添加到应用程序的更简单方法?

4

3 回答 3

1

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

@echo off
msiexec /x %1

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

于 2009-08-06T14:32:23.537 回答
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 做到这一点,但我不想学习它。

于 2009-10-12T19:13:35.300 回答
1

如果给出了某个命令行参数,另一种选择是调用 msiexec 从应用程序本身卸载 - 请参阅此处显示的示例以获取更多详细信息:http ://endofstream.com/creating-uninstaller-in-a-visual-工作室项目/

通过这种方式,您将不会在卸载时被迫看到命令提示符:)

于 2010-09-08T08:28:27.593 回答