- SharpShell_Tools.zip
- SharpShell Tools
- Apex.dll
- Apex.WinForms.dll
- ServerInspector.exe
- ServerManager.exe
- SharpShell.dll
- System.Windows.Interactivity.dll
- SharpShell_Core_Library.zip
- SharpShell_Source_Code.zip
- SharpShell Source Code
- Dependencies
- Apex
- Apex.WinForms.dll
- SharpShell
- packages
- Apex.1.5.0
- Apex.1.5.0.nupkg
- lib
- net35
- Apex.dll
- net40
- Apex.dll
- sl30
- Apex.Silverlight.dll
- sl3-wp
- Apex.WP7.dll
- sl40
- Apex.Silverlight4.dll
- sl4-wp71
- Apex.WP7.dll
- sl50
- Apex.Silverlight.dll
- NUnit.2.6.2
- repositories.config
- Samples
- ContextMenu
- CountLinesExtension
- DropHandler
- XsdDropHandler
- IconHandler
- DllIconHandler
- IconOverlayHandler
- ReadOnlyFileIconOverlayHandler
- InfoTipHandler
- FolderInfoTipHandler
- PropertySheet
- DrivePropertySheet
- TextFilePropertySheet
- SharedAssemblyInfo.cs
- SharpShell.sln
- SharpShell
- SharpShellNativeBridge
- Todo.txt
- Tools
- ServerInspector
- ServerManager
- ShellExtensionManager
|
using System;
using Microsoft.Win32;
namespace SharpShell.Diagnostics
{
/// <summary>
/// The ExplorerConfigurationManager can be used to manage explorer configuration relating to the shell.
/// </summary>
public class ExplorerConfigurationManager
{
/// <summary>
/// Initializes a new instance of the <see cref="ExplorerConfigurationManager"/> class.
/// </summary>
public ExplorerConfigurationManager()
{
// Read the configuration.
ReadConfiguration();
}
/// <summary>
/// Checks the always unload DLL value.
/// </summary>
/// <returns>True if always unload dll is set.</returns>
private static bool CheckAlwaysUnloadDll()
{
using (var alwaysUnloadDLLKey = Registry.LocalMachine.OpenSubKey(KeyName_AlwaysUnloadDll))
{
return alwaysUnloadDLLKey != null;
}
}
/// <summary>
/// Checks the desktop process value.
/// </summary>
/// <returns>True if check desktop process is set.</returns>
private static bool CheckDesktopProcess()
{
using (var explorerKey = OpenExporerSubkey(Registry.CurrentUser, RegistryKeyPermissionCheck.ReadSubTree))
{
// Do we have the value?
var value = explorerKey.GetValue(ValueName_DesktopProcess, null);
// If there's no value, or the value isn't a DWORD, it's not set.
if (value == null || value is int == false)
return false;
// We can now check the value explicitly.
return ((int)value) == 1;
}
}
/// <summary>
/// Reads the configuration.
/// </summary>
private void ReadConfiguration()
{
alwaysUnloadDll = CheckAlwaysUnloadDll();
desktopProcess = CheckDesktopProcess();
}
/// <summary>
/// Sets the always unload DLL value.
/// </summary>
private void SetAlwaysUnloadDll()
{
// Is the key there?
bool valueSet = CheckAlwaysUnloadDll();
// If we're already set correctly, we're done.
if (valueSet == alwaysUnloadDll)
return;
if (alwaysUnloadDll)
{
// Open the explorer key and create the always unload key.
using (var explorerKey = OpenExporerSubkey(Registry.LocalMachine, RegistryKeyPermissionCheck.ReadWriteSubTree))
explorerKey.CreateSubKey(SubKeyName_AlwaysUnloadDLL);
}
else
{
// Open the explorer key and delete the always unload key.
using (var explorerKey = OpenExporerSubkey(Registry.LocalMachine, RegistryKeyPermissionCheck.ReadWriteSubTree))
explorerKey.DeleteSubKeyTree(SubKeyName_AlwaysUnloadDLL);
}
}
/// <summary>
/// Sets the desktop process value.
/// </summary>
private void SetDesktopProcess()
{
// Is the key there?
bool valueSet = CheckDesktopProcess();
// If we're already set correctly, we're done.
if (valueSet == desktopProcess)
return;
if (desktopProcess)
{
// Open the explorer key and create the value.
using (var explorerKey = OpenExporerSubkey(Registry.CurrentUser, RegistryKeyPermissionCheck.ReadWriteSubTree))
explorerKey.SetValue(ValueName_DesktopProcess, 1, RegistryValueKind.DWord);
}
else
{
// Delete the key value.
using (var explorerKey = OpenExporerSubkey(Registry.CurrentUser, RegistryKeyPermissionCheck.ReadWriteSubTree))
explorerKey.DeleteValue(ValueName_DesktopProcess);
}
}
/// <summary>
/// Opens the exporer subkey.
/// </summary>
/// <param name="hiveKey">The hive key.</param>
/// <param name="permissionCheck">The permission check.</param>
/// <returns>
/// The explorer subkey.
/// </returns>
private static RegistryKey OpenExporerSubkey(RegistryKey hiveKey, RegistryKeyPermissionCheck permissionCheck)
{
// Open the explorer key with the desired permissions.
var explorerKey = hiveKey.OpenSubKey(KeyName_Explorer, permissionCheck);
// If we don't have it, we've got a critical error.
if (explorerKey == null)
throw new InvalidOperationException("Unable to open the Explorer key.");
// Return the key.
return explorerKey;
}
/// <summary>
/// The AlwaysUnloadDLL key name.
/// </summary>
private const string KeyName_AlwaysUnloadDll = @"Software\Microsoft\Windows\CurrentVersion\Explorer\AlwaysUnloadDLL";
/// <summary>
/// The AlwaysUnloadDLL sub key name.
/// </summary>
private const string SubKeyName_AlwaysUnloadDLL = @"AlwaysUnloadDLL";
/// <summary>
/// The windows explorer key namme.
/// </summary>
private const string KeyName_Explorer = @"Software\Microsoft\Windows\CurrentVersion\Explorer";
/// <summary>
/// The dekstop process value name.
/// </summary>
private const string ValueName_DesktopProcess = @"DesktopProcess";
/// <summary>
/// The always unload dll flag.
/// </summary>
private bool alwaysUnloadDll;
/// <summary>
/// The desktop process flag.
/// </summary>
private bool desktopProcess;
/// <summary>
/// Gets or sets a value indicating whether always unload DLL is set.
/// </summary>
/// <value>
/// <c>true</c> if always unload DLL is set; otherwise, <c>false</c>.
/// </value>
public bool AlwaysUnloadDll
{
get { return alwaysUnloadDll; }
set
{
alwaysUnloadDll = value;
SetAlwaysUnloadDll();
}
}
/// <summary>
/// Gets or sets a value indicating whether desktop process is set.
/// </summary>
/// <value>
/// <c>true</c> if desktop process is set; otherwise, <c>false</c>.
/// </value>
public bool DesktopProcess
{
get { return desktopProcess; }
set
{
desktopProcess = value;
SetDesktopProcess();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.