forked from dnSpy/dnSpy
-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an option to the
File
menu to restart dnSpy with administrato…
…r privileges (refs #291)
- Loading branch information
1 parent
1f0c150
commit 006e76c
Showing
5 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright (C) 2024 ElektroKill | ||
This file is part of dnSpy | ||
dnSpy is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
dnSpy is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with dnSpy. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System.ComponentModel; | ||
using System.ComponentModel.Composition; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using System.Windows.Input; | ||
using dnSpy.Contracts.App; | ||
using dnSpy.Contracts.Menus; | ||
|
||
namespace dnSpy.MainApp { | ||
[ExportMenuItem(OwnerGuid = MenuConstants.APP_MENU_FILE_GUID, Header = "res:RestartAsAdministratorCommand", Group = MenuConstants.GROUP_APP_MENU_FILE_EXIT, Order = 900000)] | ||
sealed class RestartAsAdministratorCommand : MenuItemBase { | ||
readonly IAppWindow appWindow; | ||
|
||
[ImportingConstructor] | ||
public RestartAsAdministratorCommand(IAppWindow appWindow) => this.appWindow = appWindow; | ||
|
||
public override bool IsVisible(IMenuItemContext context) => !Constants.IsRunningAsAdministrator; | ||
|
||
public override void Execute(IMenuItemContext context) { | ||
appWindow.MainWindowClosing += OnMainWindowClosing; | ||
((ICommand)ApplicationCommands.Close).Execute(context); | ||
} | ||
|
||
void OnMainWindowClosing(object? sender, CancelEventArgs args) { | ||
appWindow.MainWindowClosing -= OnMainWindowClosing; | ||
// If a different handler canceled the close operation, don't restart. | ||
if (args.Cancel) | ||
return; | ||
var location = Assembly.GetEntryAssembly()?.Location; | ||
if (location is null) { | ||
args.Cancel = true; | ||
return; | ||
} | ||
try { | ||
Process.Start(new ProcessStartInfo(location) { UseShellExecute = true, Verb = "runas" }); | ||
} | ||
catch { | ||
args.Cancel = true; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters