如何将重启操作添加到 vdproj?
我需要一个MSI文件,它会在安装结束时重新启动 PC。
这是我基于saschabeaumont的回答的解决方案。
每次构建安装程序时自动修改 .msi 以提示重新启动:
在 .vdproj 部署项目文件所在的文件夹中创建一个名为“AddRebootPrompt.vbs”的文件,VB 脚本如下所示。
在 Visual Studio 解决方案资源管理器中找到部署项目,右键单击并转到“属性”。
在 PostBuildEvent 属性中,粘贴以下内容以在构建安装程序项目后运行脚本:
cscript "$(ProjectDir)AddRebootPrompt.vbs" "$(BuiltOuputPath)"
AddRebootPrompt.vbs 内容:
Dim installer, database, view, result
Dim strPathMsi
If WScript.Arguments.Count <> 1 Then
WScript.Echo "Usage: cscript AddRebootPrompt.vbs <path to MSI>"
WScript.Quit -1
End If
strPathMsi = WScript.Arguments(0)
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (strPathMsi, 1)
Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('REBOOT', 'Force')")
WScript.Echo "Adding forced reboot prompt to install sequence."
view.Execute
database.Commit
WScript.Quit 0
如果成功,您将看到“添加强制重启提示以安装序列”。在构建安装程序项目时,在您的构建输出日志窗口中。
Just add the "REBOOT" property with the value "Force" which will prompt the user to reboot once setup is complete, or automatically reboot if there is no user interface.
If you cannot do this in the vdjproj then just use Orca to edit the Property table of the MSI once the setup is built.
If you want to force a reboot, you can set REBOOT=Force and REBOOTPROMPT=Suppress so that the user is not prompted.
Alternatively you can use the ForceReboot
action to reboot during the middle of installation or ScheduleReboot
to schedule a reboot once the installation is complete. Again either of these actions can be added using Orca if you cannot do so in the vdjproj.
You can do something like this using the following VBS
Dim installer, database, view, result
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase ("setup.msi", 1)
Set view = database.OpenView ("INSERT INTO Property (Property, Value) VALUES ('REBOOT', 'Force')")
view.Execute
database.Commit
Set database = nothing
如果您需要重新启动,Windows Installer 应该会自动检测到它。如果您因为懒得手动启动服务而想重新启动,则需要找到其他方法(我不知道有什么简单的方法)。