0

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.

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • In your expected example, the message would indicate that the process which has initiated the shutdown is now blocking the shutdown. That's even more confusing. – Thomas Weller Sep 26 '14 at 14:00
  • I would say it's a problem of the installer and should be fixed there. Instead of restarting immediately it should give the user the choice whether to restart now or later. – Thomas Weller Sep 26 '14 at 14:02
  • @ThomasW. Yes, which is why its definitely not the most transparent way of handling this situation! The real issue is that, for some reason, the VSTO installer forces a reboot, that is Microsoft's installer, the logic within it is out of my control, and I need to stop it from forcing a reboot! – Alexandru Sep 26 '14 at 14:03
  • 2
    msiexec supports [/norestart][/promptrestart][/forcerestart] – Alex K. Sep 26 '14 at 14:04
  • Aborting a shutdown using `shutdown -a` is probably not possible in this case because there's no time limit for the shutdown sequence. – Thomas Weller Sep 26 '14 at 14:10
  • @AlexK. That may prove to be quite tricky because my bootstrapper project is auto-generated and I have no clue if I can force it to pass command line arguments to MSI files it auto-downloads...I'll edit my question and show you why. – Alexandru Sep 26 '14 at 14:14

1 Answers1

0

This appears to be a ClickOnce deployment, NOT a WiX bootstrapper (Burn) application. The xml you have posted looks like it comes from a .csproj file, not a .wixproj. See if the following links help.

lordjeb
  • 1,286
  • 9
  • 14
  • No, the XML I have posted is most definitely in a .wixproj file. – Alexandru Sep 26 '14 at 15:02
  • What does your WiX package/bundle xml look like? – lordjeb Sep 26 '14 at 15:04
  • In Product.wxs, its tag followed by a tag, and no 's. Under product we have: – Alexandru Sep 26 '14 at 15:08
  • 1
    I think maybe you are trying to combine a Microsoft Bootstrapper with a WiX setup project. The links in this answer may help you avoid the reboot. Alternatively, you could look into doing a WiX bootstrapper package (http://wixtoolset.org/documentation/manual/v3/bundle/) which will let you customize the command-line of each component you are installing in your bootstrapper. – lordjeb Sep 26 '14 at 15:18
  • I think you are correct. Thanks, will look into using the WiX bootstrapper package instead of the Microsoft bootstrapper. – Alexandru Sep 26 '14 at 15:21