开发者

Customizing the VS 2008 Setup Project Uninstaller

I have a setup project for my .NET application, and both install/uninstall are working just fine, if they are left alone while they work.

However, if someone cancels th开发者_开发百科e uninstall while it is processing, the rollback doesn't seem to be handled correctly, and upon trying to uninstall again at a later time, the user is greeted with a null reference exception.

I would like to just simplify the situation; I would like to remove the user's ability to cancel an uninstall in progress. Can this be done?

Thanks, -Ben


Yes, it is possible to do so. MSDN lists several options; however, it might be simpler to just patch the MSI file created by Visual Studio. This can be done using Orca (You will find an installer for this tool in the Windows SDK folder typically under C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\orca.msi).

Orca allows you to edit the MSI database tables. To hide the cancel button you would have to add a record to the ControlCondition table (from here):

Dialog        | Control      | Action   | Condition
------------------------------------------------------
ProgressForm  | CancelButton | Hide     | 1

This manual task of adding a record using Orca is probably better done with a short VBScript like that:

Set oMsi = CreateObject("WindowsInstaller.Installer")

' get path to msi from command line
strMsiFullPath = Wscript.Arguments(0)
' open transacted
Set oDB = oMsi.OpenDatabase(strMsiFullPath , 1)

' insert a record into the [ControlCondition][3] table
Set oView = oDB.OpenView("INSERT INTO `ControlCondition` " & _
    "(`ControlCondition`.`Dialog_`, `ControlCondition`.`Control_`," & _
     "`ControlCondition`.`Action`, `ControlCondition`.`Condition`) " & _
     "VALUES ('ProgressForm', 'CancelButton', 'Hide', '1')")

' clean up
oView.Execute: oView.Close: oDB.Commit
Set oMsi = Nothing

This script can be added as a post-build step to your setup project (Note that there is a typo in the Visual Studio variable for the output path):

cscript $(ProjectDir)patch.vbs $(BuiltOuputPath)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜