Open kmackey1 opened 4 years ago
Thanks for the tip that Programs and Features may be using a Job.
I found a C# fix using Win32_Process.Create:
using System.Management; // ObjectGetOptions, ManagementPath, ManagementClass
. . .
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
. . .
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass classInstance = new ManagementClass(managementPath, objectGetOptions);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
string installDir = Bootstrapper.Engine.FormatString(Bootstrapper.Engine.StringVariables["InstallDir"]);
string pathAndFile = Path.Combine(installDir, "myapp.exe");
inParams["CommandLine"] = pathAndFile;
try
{
ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
UInt32 result = (UInt32)outParams["ReturnValue"];
if (result != 0)
{
this.Bootstrapper.Engine.Log(LogLevel.Standard, $"Error from Win32_Process.Create when attempting to start myapp. Error code: " + result.ToString());
return;
}
UInt32 processId = (UInt32)outParams["ProcessId"];
IntPtr hwndToMyApp = GetWindowHandleFromProcessId(processId); // Uses EnumWindows and GetWindowThreadProcessId.
SetForegroundWindow(hwndToMyApp); // Bring window to top so user can see it.
}
catch (System.Exception e)
{
this.Bootstrapper.Engine.Log(LogLevel.Standard, $"Error when attempting to start myapp: {e} File: " + pathAndFile);
}
Please provide answers to the following questions to help us narrow down, reproduce, and fix the problem. Fill out one section and delete the others.
3.11.1.2318
15.9.19 2017
1.0.0.4
4.8.03752
Windows 7 and Windows 10
Note that this only happens using Programs and Features on Windows 10 and Windows 7, and not Apps and Features on Windows 10.
It also only happens with Launch after Repair and not Launch after a fresh install, so something about the way Programs and Features launches the standard bootstrapper when choose Change.
The error appears even if Launch opens a non-product application like Notepad.
I originally found the bug when using my custom bootstrapper, which targets .Net 3.5.
It's an edge case, but would be nice if there was a fix.
No error message when choose to Change or Uninstall.