Skip to content

Commit c4e031e

Browse files
committed
Fix duplicate window and cancel dialog bugs
Bug Fixes: 1. Fixed cancel button opening new window instead of exiting - Changed ShowInstallationScopeDialog to return bool - Return false on cancel, true on continue - Close form immediately in constructor when cancelled - Prevents form from showing after user cancels 2. Fixed duplicate windows when selecting system-wide installation - Changed from Application.Exit() to Environment.Exit(0) - Ensures immediate process termination after starting elevated instance - Prevents non-elevated instance from continuing to run - Only elevated instance remains open Technical Changes: - ShowInstallationScopeDialog now returns bool success status - Constructor checks return value and closes form if cancelled - Use Environment.Exit(0) for successful elevation restart - Use Environment.Exit(1) for failed elevation - Immediate termination prevents race conditions
1 parent ddca811 commit c4e031e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

MainForm.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ public MainForm()
130130
else
131131
{
132132
// Show dialog for user to choose
133-
ShowInstallationScopeDialog();
133+
if (!ShowInstallationScopeDialog())
134+
{
135+
// User cancelled - close immediately without showing form
136+
this.Load += (s, e) => this.Close();
137+
return;
138+
}
134139
}
135140

136141
CheckAdminPrivileges();
@@ -330,7 +335,7 @@ private void InitializeComponent()
330335
this.Controls.AddRange(new Control[] { headerPanel, statusLabel, speedLabel, progressBar, logTextBox, buttonPanel });
331336
}
332337

333-
private void ShowInstallationScopeDialog()
338+
private bool ShowInstallationScopeDialog()
334339
{
335340
var scopeForm = new Form
336341
{
@@ -433,11 +438,12 @@ private void ShowInstallationScopeDialog()
433438
var scopeText = installationScope == InstallationScope.User ? "user-level" : "system-wide";
434439
LogMessage($"Installation scope selected: {scopeText}");
435440
statusLabel.Text = $"Ready to install ({scopeText})";
441+
return true;
436442
}
437443
else
438444
{
439445
LogMessage("Installation cancelled by user");
440-
Application.Exit();
446+
return false;
441447
}
442448
}
443449

@@ -463,15 +469,15 @@ private void CheckAdminPrivileges()
463469
};
464470

465471
Process.Start(startInfo);
466-
Application.Exit();
472+
Environment.Exit(0); // Immediate exit to prevent duplicate windows
467473
}
468474
catch (Exception ex)
469475
{
470476
// User cancelled UAC prompt or other error
471477
LogMessage($"Failed to elevate privileges: {ex.Message}");
472478
MessageBox.Show("Administrator privileges are required for system-wide installation.\n\nPlease approve the UAC prompt or choose User Installation instead.",
473479
"Administrator Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
474-
Application.Exit();
480+
Environment.Exit(1);
475481
}
476482
}
477483
else

0 commit comments

Comments
 (0)