About Me

My photo
Dhaka, Bangladesh
I am B.S.C Engineer,CSE,SUST and Ex-Cadet of Mirzapur Cadet College.

Wednesday, April 8, 2009

Create a system folder in My Computer with C#

I found a article to create a system folder in "My Computer" in http://www.technospot.net/blogs/how-to-create-a-system-folder-in-my-computer/.

However, I have successfully done it with a Console app of C# for my own purpose.:)

Also, I have redirected it to open up a particular page with OS default browser.

Steps(Manual):

Step 1: 

Create a Unique Key Open registry with “regedit” command on run window.
Navigate to HKEY_CLASSES_ROOT\CLSID\. Then right click and create a new key with value as {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}

Now set the default value of this key to the folder name you want to use. Now your path will look like ( I will call this as parent key throughout the discussion) HKEY_CLASSES_ROOT\CLSID\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}

Step 2: 
Add Custom Icon to the folder 
Now create a sub key under parent key.
Name it as “DefaultIcon”.
Set the default value of this to the path of the icon image you want to use.
If you dont specify your icon, system will take default icon.

Step 3: 
Adding attributes Under parent key 
create another key with name as “InprocServer32″
Set the default value as “shell32.dll”
Again at the same level create another folder as “ThreadingModel” and set its value as “Apartment”
 Same way create another key (under parent level) at the same level with structure as \Shell\My Folder\Command
 Set the default value here as “explorer /root,c:\Blog Data”
 This has to be same which you gave when you created the first key.
  
 Step 4 
Adding Handlers
Under parent key, create another key as \ShellEx\PropertySheetHandlers\ {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}
Similar way another key is to added to parent key as “Shell Folder”
In this right click and create new binary value called as “Attributes” with value as 00 00 00 00.
 
Step 5: 
Settings to place in My Computer
Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
Then to \CurrentVersion\Explorer\MyComputer\NameSpace\
Add the parent key which in this case is {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}











CODE:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
//Step1
/*
Create a Unique Key Open registry with “regedit” command on run window.
Navigate to HKEY_CLASSES_ROOT\CLSID\. Then right click and create a new key with value as {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}
*/
            
    Microsoft.Win32.RegistryKey RootKey;
            RootKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID", true);
            
            Microsoft.Win32.RegistryKey FolderKey = RootKey.CreateSubKey("{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12341}");
            FolderKey.SetValue("", "PrologLive NetSpace(1GB Space)",Microsoft.Win32.RegistryValueKind.String);
            
            FolderKey.Flush();

            
            
            //Step2
            /*
             * Add Custom Icon to the folder.
                Now create a sub key under parent key.
                Name it as “DefaultIcon”.
                Set the default value of this to the path of the icon image you want to use.
             * */
          

            Microsoft.Win32.RegistryKey DefaultIconKey = FolderKey.CreateSubKey("DefaultIcon");
            DefaultIconKey.SetValue("", "/Resources/Bitmap1.bmp");
            DefaultIconKey.SetValue("","logo.ico");

            //Step3
            /*
             * Under parent key create another key with name as “InprocServer32″
                Set the default value as “shell32.dll”
             * */

            Microsoft.Win32.RegistryKey InprocServer32Key = FolderKey.CreateSubKey("InprocServer32");
            InprocServer32Key.SetValue("", "shell32.dll");

            /*
             * Again at the same level create another folder as “ThreadingModel” and set its value as “Apartment”
             * */

            Microsoft.Win32.RegistryKey ThreadingModelKey = FolderKey.CreateSubKey("ThreadingModel");
            ThreadingModelKey.SetValue("", "Apartment");

            /*
             * Same way create another key (under parent level) at the same level with structure as 
             * \Shell\My Folder\Command
                Set the default value here as “explorer /root,c:\Blog Data”
             * */
            Microsoft.Win32.RegistryKey ShellKey = FolderKey.CreateSubKey("Shell");
            


            

            Microsoft.Win32.RegistryKey MyFolderKey = ShellKey.CreateSubKey("MyFolder");
            
            

            Microsoft.Win32.RegistryKey CommandKey = MyFolderKey.CreateSubKey("Command");
            CommandKey.SetValue("","explorer /root, http://www.prologinc.com/");

            
            


            /*
             * Step 4 Adding Handlers
                Under parent key, create another key as \ShellEx\PropertySheetHandlers\ {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}
                
             * */


            Microsoft.Win32.RegistryKey ShellExKey = FolderKey.CreateSubKey("ShellEx");

            

            Microsoft.Win32.RegistryKey PropertySheetHandlersKey = ShellExKey.CreateSubKey("PropertySheetHandlers");

            

            Microsoft.Win32.RegistryKey FinalFolderKey = PropertySheetHandlersKey.CreateSubKey("{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12341}");

            /*
             Similar way another key is to added to parent key as “Shell Folder”
                In this right click and create new binary value called as “Attributes” with value as 00 00 00 00.
             */
            Microsoft.Win32.RegistryKey ShellFolderKey = FolderKey.CreateSubKey("Shell Folder");


            

            ShellFolderKey.SetValue("Attributes", new byte[] {00, 00, 00, 00},  Microsoft.Win32.RegistryValueKind.Binary);
            

            /*
             * Step 5: Settings to place in My Computer
                Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
                Then to \CurrentVersion\Explorer\MyComputer\NameSpace\
                Add the parent key which in this case is {FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}
             */


            Microsoft.Win32.RegistryKey RootForMicroSoftKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software",true);
            Microsoft.Win32.RegistryKey RootForWindowsKey = RootForMicroSoftKey.OpenSubKey("Microsoft", true);
            Microsoft.Win32.RegistryKey RootForCurrentVersionKey = RootForWindowsKey.OpenSubKey("Windows", true);

            Microsoft.Win32.RegistryKey CurrentVersionKey = RootForCurrentVersionKey.CreateSubKey("CurrentVersion");

            
            Microsoft.Win32.RegistryKey ExplorerKey = CurrentVersionKey.CreateSubKey("Explorer");

            
            Microsoft.Win32.RegistryKey MyComputerKey = ExplorerKey.CreateSubKey("MyComputer");

          
            Microsoft.Win32.RegistryKey NameSpaceKey = MyComputerKey.CreateSubKey("NameSpace");

          
            Microsoft.Win32.RegistryKey MainFolderKey = NameSpaceKey.CreateSubKey("{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12341}");


            /*
             * Close All Key
             */

            FolderKey.Close();
            RootKey.Close();
            MainFolderKey.Close();
            NameSpaceKey.Close();
            MyComputerKey.Close();
            ExplorerKey.Close();
            CurrentVersionKey.Close();
            RootForCurrentVersionKey.Close();
            RootForWindowsKey.Close();
            RootForMicroSoftKey.Close();
            ShellFolderKey.Close();
            FinalFolderKey.Close();
            PropertySheetHandlersKey.Close();
            ShellExKey.Close();
            CommandKey.Close();
            MyFolderKey.Close();
            ShellKey.Close();
            ThreadingModelKey.Close();
            InprocServer32Key.Close();
            DefaultIconKey.Close();
        }
    }
}

1 comment:

Unknown said...

Hello. Thank you for your post. It was very helpful for me. But I still have one qustion and can't find answer. By default my custom system folders places in 'Others' category. Can I create a custom category in My Computer folder (like 'Files stored on this computer' or 'Hard Disk Drives')?