diff --git a/ILSpy/Options/MiscSettings.cs b/ILSpy/Options/MiscSettings.cs
index a64a9e4c0..4802b9d3a 100644
--- a/ILSpy/Options/MiscSettings.cs
+++ b/ILSpy/Options/MiscSettings.cs
@@ -67,42 +67,32 @@ namespace ICSharpCode.ILSpy.Options
public ICommand AddRemoveShellIntegrationCommand { get; }
+ const string rootPath = @"Software\Classes\{0}\shell";
+ const string fullPath = @"Software\Classes\{0}\shell\Open with ILSpy\command";
+
private void AddRemoveShellIntegration(object obj)
{
- if (!IsElevated()) {
- MessageBox.Show(Properties.Resources.RestartElevatedMessage, "ILSpy", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- string commandLine = NativeMethods.ArgumentArrayToCommandLine(Assembly.GetEntryAssembly().Location, "%L");
+ string commandLine = NativeMethods.ArgumentArrayToCommandLine(Assembly.GetEntryAssembly().Location) + " \"%L\"";
if (RegistryEntriesExist()) {
if (MessageBox.Show(string.Format(Properties.Resources.RemoveShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
- Registry.ClassesRoot.CreateSubKey(@"dllfile\shell").DeleteSubKeyTree("Open with ILSpy");
- Registry.ClassesRoot.CreateSubKey(@"exefile\shell").DeleteSubKeyTree("Open with ILSpy");
+ Registry.CurrentUser.CreateSubKey(string.Format(rootPath, "dllfile")).DeleteSubKeyTree("Open with ILSpy");
+ Registry.CurrentUser.CreateSubKey(string.Format(rootPath, "exefile")).DeleteSubKeyTree("Open with ILSpy");
}
} else {
if (MessageBox.Show(string.Format(Properties.Resources.AddShellIntegrationMessage, commandLine), "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
- Registry.ClassesRoot.CreateSubKey(@"dllfile\shell\Open with ILSpy\command")?
+ Registry.CurrentUser.CreateSubKey(string.Format(fullPath, "dllfile"))?
.SetValue("", commandLine);
- Registry.ClassesRoot.CreateSubKey(@"exefile\shell\Open with ILSpy\command")?
+ Registry.CurrentUser.CreateSubKey(string.Format(fullPath, "exefile"))?
.SetValue("", commandLine);
}
}
OnPropertyChanged(nameof(AddRemoveShellIntegrationText));
-
- bool IsElevated()
- {
- try {
- return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
- } catch (System.Security.SecurityException) {
- return false;
- }
- }
}
private static bool RegistryEntriesExist()
{
- return Registry.ClassesRoot.OpenSubKey(@"dllfile\shell\Open with ILSpy\command") != null
- && Registry.ClassesRoot.OpenSubKey(@"exefile\shell\Open with ILSpy\command") != null;
+ return Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "dllfile")) != null
+ && Registry.CurrentUser.OpenSubKey(string.Format(fullPath, "exefile")) != null;
}
public string AddRemoveShellIntegrationText {
diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs
index 75a7fbecb..267bf70dd 100644
--- a/ILSpy/Properties/Resources.Designer.cs
+++ b/ILSpy/Properties/Resources.Designer.cs
@@ -295,7 +295,7 @@ namespace ICSharpCode.ILSpy.Properties {
}
///
- /// Looks up a localized string similar to This will add "{0}" to the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
+ /// Looks up a localized string similar to This will add "{0}" to the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
///
///Do you want to continue?.
///
@@ -1696,7 +1696,7 @@ namespace ICSharpCode.ILSpy.Properties {
}
///
- /// Looks up a localized string similar to This will remove "{0}" from the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command".
+ /// Looks up a localized string similar to This will remove "{0}" from the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command".
///
///Do you want to continue?.
///
@@ -1733,15 +1733,6 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
- ///
- /// Looks up a localized string similar to Please restart ILSpy.exe as administrator to execute this function!.
- ///
- public static string RestartElevatedMessage {
- get {
- return ResourceManager.GetString("RestartElevatedMessage", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to Save.
///
diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx
index 54d8d5a92..de2f7a957 100644
--- a/ILSpy/Properties/Resources.resx
+++ b/ILSpy/Properties/Resources.resx
@@ -840,7 +840,7 @@ Please disable all filters that might hide the item (i.e. activate "View > Sh
Add shell integration
- This will add "{0}" to the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
+ This will add "{0}" to the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command" to allow opening .dll and .exe files from the Windows Explorer context menu.
Do you want to continue?
@@ -848,11 +848,8 @@ Do you want to continue?
Remove shell integration
- This will remove "{0}" from the registry at "HKCU\dllfile\shell\Open with ILSpy\command\" and "HKCU\exefile\shell\Open with ILSpy\command".
+ This will remove "{0}" from the registry at "HKCU\Software\Classes\dllfile\shell\Open with ILSpy\command" and "HKCU\Software\Classes\exefile\shell\Open with ILSpy\command".
Do you want to continue?
-
- Please restart ILSpy.exe as administrator to execute this function!
-
\ No newline at end of file