Click here to Skip to main content
Click here to Skip to main content

Tagged as

Metro Style Toggle for Windows 8 Developer Preview

, 4 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Toggle between Windows 8 Developer Preview Metro Style (Start menu and Explorer Ribbon) and Classic Windows 7 Shell.

Introduction

MetroStyleToggle

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 using Microsoft.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 the RPEnabled Registry value. So for example, If the user wants to switch back to Metro, then RPEnabled should be updated to become 1.
  • 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 Smile with tongue out, 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

2

Classic Windows 7 Style

1

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. Smile

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bander Alsharfi [MVP]
Architect
Jordan Jordan

I am a huge fan of the Barcelona football team and the Spanish football league. I love socializing with my IT peers and solving programming challenges. I was part of my university ACM ICPC team twice. In addition I’m addicted to workshops, presentations, and proof of concepts. Working hard on that, Microsoft awarded me the MVP award 4 years.


I remember the first time I wanted to be an MVP was during the Microsoft campaign for Longhorn. Watching these guys on stage presenting the future was a thrilling experience for me. I just wanted to be that guy who climbs the stage; tell people about new features; fires up a virtual machine and demo great stuff; answer their questions, and throw giveaways at them! Being an MVP gave me the adrenalin rush and satisfaction I was looking for. Later I presented in many Microsoft regional events, such as East Med Developers Conference, Momentum, Partner Readiness, Visual Studio Tour, and Academic Day with a total of more than 400 sessions.

Technically, I’m in love with my wifeSmile | :) , SharePoint, and BizTalk! I specialize also in Enterprise Project Management (Project Server and Portfolio Server); Visual Studio Team System; Customer Care Framework (CCF), and Hyper-V. In addition to my technical knowledge, I have excellent experience with Governance, Risk Management, and Compliance (GRC) and IT Service Management (ITSM). I’m ITIL v3 certified and I have wide experience working with MOF and COBIT.

Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 1 PinmemberKuntalBose29-Apr-14 0:13 
GeneralMy vote of 5 PinmemberFarhan Ghumra28-Jun-12 22:35 
SuggestionThank you PinmemberResul Cavusoglu28-Dec-11 21:38 
GeneralSimilar functionality in all native code Pinmemberghostrider139-Nov-11 9:05 
GeneralHELP PinmemberJamesHollowell8-Nov-11 11:49 
AnswerSolved PinmemberHansHank29-Dec-11 6:05 
GeneralMy vote of 1 Pinmemberrobertw0195-Nov-11 17:50 
GeneralRe: My vote of 1 PinmemberBander Alsharfi [MVP]6-Nov-11 8:27 
GeneralMy vote of 5 PinmemberFlorian Rappl4-Nov-11 10:21 
GeneralMy vote of 5 PinmemberJulien Villers4-Nov-11 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 4 Nov 2011
Article Copyright 2011 by Bander Alsharfi [MVP]
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid