5

I want to add my own custom file extension into the win 7 registry. And I also want to add a right click option "Play with xPlayer" for this extension.

I want to use it in my C# application. How can I do it using the registry?

2
  • The question is offtopic here and belongs to superuser.com . The easiest way is to run regedit, check HKEY_CLASSES key for say ".mp3" subkey and see how it works. Feb 8, 2011 at 22:33
  • Sorry I forgot to say I want to use it in my C# application. And actually I have been doing exactly what you said for some hours now. But I can see here different type of pattern. So I need to know the standard way to do this.
    – Barun
    Feb 8, 2011 at 22:37

1 Answer 1

9

MSDN has extensive documentation on how to work with file extensions in the Registry. Start with these articles:

File Types and File Associations

Guidelines for File Associations and Default Programs

Update: You would need to create the following Registry keys and values at a bare minimum (file extension registrations support a LOT of features):

HKEY_CURRENT_USER\Software\Classes\.myext
(Default) = "MyAppExt"

HKEY_CURRENT_USER\Software\Classes\MyAppExt\shell\PlayWithXPlayer
(Default) = "Play with xPlayer"

HKEY_CURRENT_USER\Software\Classes\MyAppExt\shell\PlayWithXPlayer\command
(Default) = ""c:\path to\xplayer.exe" "%1""

Substitute HKEY_LOCAL_MACHINE if you want your file extension to be accessible to all users on the PC, instead of just the user that is running your app/installer.

For example:

using System;
using Microsoft.Win32;

// substitute "HKEY_LOCAL_MACHINE" if needed...
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Classes\\.xpl", "", "xPlayer", RegistryValueKind.String);
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Classes\\xPlayer\\shell\\PlayWithXPlayer", "", "Play with xPlayer", RegistryValueKind.String);
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Classes\\xPlayer\\shell\\PlayWithXPlayer\\command", "", "\"c:\\path to\\xplayer.exe\" \"%1\"", RegistryValueKind.String);

Alternatively:

using System;
using Microsoft.Win32;

// substitute Registry.LocalMachine if needed...
RegistryKey rkRootKey = Registry.CurrentUser;

RegistryKey rk = rkRootKey.CreateSubKey("Software\\Classes\\.xpl");
rk.SetValue("", "xPlayer", RegistryValueKind.String);
rk.Close();

rk = rkRootKey.CreateSubKey("Software\\Classes\\xPlayer\\shell\\PlayWithXPlayer");
rk.SetValue("", "Play with xPlayer", RegistryValueKind.String);

RegistryKey rk2 = rk.CreateSubKey("command");
rk2.SetValue("", "\"c:\\path to\\xplayer.exe\" \"%1\"", RegistryValueKind.String);
rk2.Close();

rk.Close();

When your player app is started, it can look at its command-line parameters, and if it sees a filename passed in, it can play the file as needed.

2
  • Thanks for answering. I didn't upvote (nor downvote) because this answer is just links. Links, especially to Microsoft pages, tend to die, leading to a useless answer. If you added some examples here in the answer itself, I'd upvote it. Sep 16, 2015 at 18:52
  • @ChrisMoschini: done. Sep 17, 2015 at 1:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .