Metro Style Toggle for Windows 8 Developer Preview






3.58/5 (10 votes)
Toggle between Windows 8 Developer Preview Metro Style (Start menu and Explorer Ribbon) and Classic Windows 7 Shell.
Introduction

I have been running Windows 8 Developer Preview for a while now. Since my laptop does not support touch, I am stuck with the new Metro style Start menu. Honestly, it rocks on touch! but I prefer the classic Start menu of Windows 7.
I surfed the web for a while looking up a way to disable the new metro Start menu and use the classic Windows 7 instead. Many websites pointed out that it is controlled through the Windows Registry under HKEY_CURRENT_USER\Software\Microsoft\Windows\ CurrentVersion\Explorer using the Value of RPEnabled. Metro’s value is 1 and classic Windows 7 is 0.
I decided to ease the toggle by writing an application (called it “Metro Style Toggle”) that updates the RPEnabled registry value. In this post, I will share how I managed to read/write Windows Registry values to switch between the shell styles.
Background
To quickly summarize the code:
- Read the
RPEnabled
Registry value usingMicrosoft.Win32.Registry.GetValue
and reflect the state on the UI by updating the status label and disabling the current status toggle button. So for example, if the current status is Metro, then the Metro toggle should be disabled. - When the user toggles the state, I use
Microsoft.Win32.Registry.SetValue
to update theRPEnabled
Registry value. So for example, If the user wants to switch back to Metro, thenRPEnabled
should be updated to become1
. - An alert is displayed to the user asking them to restart their machine for changes to take effect.
I wrote the code to run on the Windows 8 Developer Preview, I have no clue if it will run on the Beta or RTM releases. Furthermore, you have to run this application as an Administrator, otherwise it will fail to update the Windows Registry (It worked with me without Administrative privileges, maybe because I am the administrator , still better to run it as Administrator). Please note that Windows might ask you to install Microsoft .NET Framework 3.5 with SP1 using the Windows Features Activation if you have not activated the runtime yet.
Metro Style
Classic Windows 7 Style
Source Code
The easiest way for me to explain the source code was to comment on it and paste it here. So for you geeks who are interested in the source code, let’s start digging:
using System;
using Microsoft.Win32;
//Used for Registry.GetValue() and Registry.SetValue() - Lines 78 and 88
using System.Windows.Forms;
using System.Diagnostics;
//Used for Process.Start() - Line 134
namespace MetroStyleToggle
{
public partial class ToggleControl : Form
{
public ToggleControl()
{
InitializeComponent();
}
enum ShellStatus { Metro, Classic, Unknown }
ShellStatus currentShellStatus;
string registryPath = @"HKEY_CURRENT_USER\Software\Microsoft\
Windows\CurrentVersion\Explorer",
registryValue = "RPEnabled";
string metroStyle = "1", classicStyle = "0", currentKeyValue = "",
restartMessege = "Restart needed for updates to take effect.";
private void ToggleControl_Load(object sender, EventArgs e)
{
SetShellStatusMessege();
}
private void SetShellStatusMessege()
{
//Get the current shell style state from Windows Registry and
// store it inside currentKeyValue
//You will find more explanation about the GetRegistryValue function
// whereabouts below
currentKeyValue = GetRegistryValue(registryPath, registryValue);
//Maintain the current shell style state
SetShellStatus(currentKeyValue);
//Update the shell status label with the current shell style state
ShellStatusMessege.Text = currentShellStatus.ToString();
}
private void SetShellStatus(string status)
{
if (status == metroStyle)
{
//Set the shell style state to Metro
currentShellStatus = ShellStatus.Metro;
//Disable the MetroToggle button
MetroToggle.Enabled = false;
//Enable the ClassicToggle button
ClassicToggle.Enabled = true;
}
else if (status == classicStyle)
{
//Set the shell style state to Classic
currentShellStatus = ShellStatus.Classic;
//Enable the MetroToggle button
MetroToggle.Enabled = true;
//Disable the ClassicToggle button
ClassicToggle.Enabled = false;
}
else
{
//Set the shell style state to Unknown
currentShellStatus = ShellStatus.Unknown;
}
}
public string GetRegistryValue(string path, string value)
{
//Return the Windows Registry value using the Path set in
// registryPath and registryValue
//registryPath value is
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
//registryValue value is RPEnabled
//If the key does not exist, the return value will be "Unknown"
return Convert.ToString(Registry.GetValue(path, value, "Unknown"));
}
public void SetRegistryValue(string path, string value, string shell)
{
//Write to Windows Registry using the
//Path set in registryPath and registryValue
//registryPath value is
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
//registryValue value is RPEnabled
//shell contains either 0 for Classic Windows 7 Style or 1 for Metro Style
Registry.SetValue(path, value, shell);
}
private void MetroToggle_Click(object sender, EventArgs e)
{
try
{
//Set the shell style state to Classic, classicStyle was set to 1
SetRegistryValue(registryPath, registryValue, metroStyle);
//Update the status label
SetShellStatusMessege();
//Alert the user to restart their machine
MessageBox.Show(restartMessege,this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
//Capture the error and push it to the status label
ShellStatusMessege.Text = "Error: " + ex.Message;
}
}
private void ClassicToggle_Click(object sender, EventArgs e)
{
try
{
//Set the shell style state to Classic, classicStyle was set to 0
SetRegistryValue(registryPath, registryValue, classicStyle);
//Update the status label
SetShellStatusMessege();
//Alert the user to restart their machine
MessageBox.Show(restartMessege, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
//Capture the error and push it to the status label
ShellStatusMessege.Text = "Error: " + ex.Message;
}
}
private void BlogLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//Launch the user's default browser and browse to my blog URL.
//BlogLink is a LinkButton and it's Text property
// is set to http://www.sharepointstack.com/
Process.Start(BlogLink.Text);
}
}
}
Well, that’s it.