2009-08-06 167 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做到這一點,但我不想去了解它。

相關問題