I have a Windows installation bootstrapper, setup.exe
. It functions to download and install Microsoft prerequisites (.NET Framework 3.5, Microsoft Visual Studio Tools for Office Runtime (VSTO), etc). The VSTO is problematic because on some host Windows OS versions it forces a reboot. This may cause customers to be quite upset because they don't have time to save their work. As a result, I need to stop this behavior.
In C#, is there any way to block another process from rebooting Windows?
The only useful way around this that I have found to work has been by P/Invoking ShutdownBlockReasonCreate. But this isn't transparent enough, because this method blocks shutdowns for a particular process, not the same process as the one that is causing the shutdown, so its annoying because the user is presented with an OS shutdown screen, and in that screen the list of running processes, the one that is blocking the shutdown, and buttons to either cancel or continue the shutdown. I was hoping there would be a more transparent way of handling this.
Edit: As another Alex mentioned, msiexec supports [/norestart][/promptrestart][/forcerestart]. However, in my WiX project, I have no clue how to pass command line arguments to the MSI that installs these prerequisites. My bootstrapper, setup.exe
is generated as follows:
<Target Name="AfterBuild">
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<BootstrapperFile Include="Microsoft.Net.Framework.3.5.SP1">
<ProductName>.NET Framework 3.5 SP1</ProductName>
</BootstrapperFile>
<BootstrapperFile Include="Microsoft.VSTORuntime.4.0">
<ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64)</ProductName>
</BootstrapperFile>
</ItemGroup>
</BootstrapperFile>
<GenerateBootstrapper ApplicationFile="$(TargetFileName)" ApplicationName="My Application" BootstrapperItems="@(BootstrapperFile)" ComponentsLocation="HomeSite" CopyComponents="False" OutputPath="$(OutputPath)" Path="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\BootStrapper" ApplicationRequiresElevation="True" Culture="en-US" Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' " />
</Target>
The above is located in my .wixproj file.