Fix direct window launch when VBScript is disabled
The window now starts Luminary.ps1 through a hidden PowerShell process instead of relying on the VBS entry point, and the installer defaults to Luminary.cmd. Bump the beta to 0.5.1.
This commit is contained in:
@@ -39,7 +39,7 @@ internal static class Program
|
||||
|
||||
MessageBox.Show(
|
||||
"LuminaryWindow.exe is only the app window.\n\n" +
|
||||
"Start Luminary.exe (or Luminary.cmd) from the Luminary folder instead.",
|
||||
"Start Luminary.cmd (or Luminary.vbs) from the Luminary folder instead.",
|
||||
"Luminary",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
@@ -63,25 +63,69 @@ internal static class Program
|
||||
// Environment.ProcessPath is the exe itself even in a single-file publish;
|
||||
// AppContext.BaseDirectory is only a fallback.
|
||||
var root = Path.GetDirectoryName(Environment.ProcessPath) ?? AppContext.BaseDirectory;
|
||||
foreach (var name in new[] { "Luminary.exe", "Luminary.vbs", "Luminary.cmd" })
|
||||
|
||||
// A Go build has one native launcher; use it when present.
|
||||
var native = Path.Combine(root, "Luminary.exe");
|
||||
if (File.Exists(native) && TryStart(native, root)) return true;
|
||||
|
||||
// Do not go through Luminary.vbs here. Windows Script Host can be
|
||||
// disabled by policy, which makes the window fail even though the
|
||||
// bundle is healthy. Run the PowerShell launcher hidden instead; it is
|
||||
// the same code Luminary.cmd uses and needs no console or .vbs handler.
|
||||
var script = Path.Combine(root, "Luminary.ps1");
|
||||
if (File.Exists(script))
|
||||
{
|
||||
var launcher = Path.Combine(root, name);
|
||||
if (!File.Exists(launcher)) continue;
|
||||
var powershell = Path.Combine(
|
||||
Environment.SystemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
|
||||
if (!File.Exists(powershell)) powershell = "powershell.exe";
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(launcher)
|
||||
var start = new ProcessStartInfo(powershell)
|
||||
{
|
||||
WorkingDirectory = root,
|
||||
UseShellExecute = true,
|
||||
});
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
};
|
||||
start.ArgumentList.Add("-NoProfile");
|
||||
start.ArgumentList.Add("-ExecutionPolicy");
|
||||
start.ArgumentList.Add("Bypass");
|
||||
start.ArgumentList.Add("-WindowStyle");
|
||||
start.ArgumentList.Add("Hidden");
|
||||
start.ArgumentList.Add("-File");
|
||||
start.ArgumentList.Add(script);
|
||||
Process.Start(start);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Try the next entry point before giving up.
|
||||
// Fall through to the command entry point.
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var name in new[] { "Luminary.cmd", "Luminary.vbs" })
|
||||
{
|
||||
var launcher = Path.Combine(root, name);
|
||||
if (File.Exists(launcher) && TryStart(launcher, root)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryStart(string launcher, string workingDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(launcher)
|
||||
{
|
||||
WorkingDirectory = workingDirectory,
|
||||
UseShellExecute = true,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user