DCSIMG
Windows 7: Register a New File Associations - Guy Burstein's Blog

Guy Burstein's Blog

Developer Evangelist @ Microsoft

News

Guy Burstein The Bu

Disclaimer
Postings are provided 'As Is' with no warranties and confer no rights.

Guy Burstein LinkedIn Profile

TwitterCounter for @bursteg

Links

Articles

Blogs I Read

Windows 7: Register a New File Associations

Windows 7: Register a New File Associations

Windows 7: Register a New File Associations

Windows 7: Register a New File Associations Lets say I have a standard Windows Forms application that works with .guy file types (which is nothing but a text file):

This application can be launched from the command line with a file name as an argument:

> TextFilesViewer.exe SampleFile.guy

In this case, the application displays the file contents in the multiline textbox above:

private void ViewerForm_Load(object sender, EventArgs e)

{

  string[] args = Environment.GetCommandLineArgs();

  if (args.Length > 1)

  {

    string[] lines = File.ReadAllLines(args[1]);

    this.txtFileContents.Lines = lines;

  }

}

Since this application is the only application that knows how to work with .guy files, we would like to associate this file type with my application.

Windows 7: Register a New File Associations

In order to do that, add a reference to the RegistrationHelper sample. This is an exe that performs the actual registration of the file association and needs to be run with admin privileges. It can be found as a sample project in the WindowsAPICodePack\Samples\Shell\TaskbarDemo\CS\RegistrationHelper folderer

After you have added the reference you should add another file from the samples folder - RegistrationHelper.cs which is found in the WindowsAPICodePack\Samples\Shell\TaskbarDemo\CS\TaskbarDemo\ folder.
This file exposes several static methods that invoke the helper as another process with admin privileges.

private void registerFileTypeToolStripMenuItem_Click(object sender, EventArgs e)

{

  string appId = "TextFilesViewer";

 

  RegistrationHelper.RegisterFileAssociations(

    appId,

    false,

    appId,

    string.Format("{0} %1", Assembly.GetExecutingAssembly().Location),

    ".guy");

}

Notice that one of the parameters of RegistrationHelper.RegisterFileAssociations() method is the Application ID which is set to a meaningful name. I’ll talk more on the Application ID in later posts to understand its impact on additional features.

Windows 7: Register a New File AssociationsWhen the user tries to associate the file type, RegistratioinHelper will require admin privileges. If User Account Control (UAC) is enabled on your machine, you will be prompted to allow the registration utility to modify the registry.

After the registration completes, you can double click and .guy files in your machine, and the TextFilesViwer application will be launched to display its content.

Enjoy!

Comments

exspymannn said:

Hello to everyone.

# July 2, 2009 1:34 AM

Ontogehen said:

Hello World I'm new here! Thanks for having me on board :)

# July 4, 2009 2:07 AM

carlosgatesh said:

# July 5, 2009 4:53 AM

Windows 7: Register a New File Associations - Guy Burstein's Blog | Windows (7) Affinity said:

Pingback from  Windows 7: Register a New File Associations - Guy Burstein's Blog | Windows (7) Affinity

# July 6, 2009 4:32 AM

SignoriniCoCo said:

Buy Online  azulfidine  on static-pharama.com

Buy Online  starlix  on static-pharama.com

# July 7, 2009 3:52 AM

ednaakriss said:

Hi all

I`m Edna, 22yo chick from Denver, Texas. I`m working in net marketing company and I like hip hop.

[url=naturalteethwhitening.weebly.com]Teeth Whitening[/url]

# July 7, 2009 6:07 PM

dailyadultscom said:

Only for us ppl:[url=http://maxim.usgame.org] Here u can get for free 12 months subscription to MAXIM magazine[/url]

# July 8, 2009 12:38 PM

jackiebrenttz said:

I`m new user here

# July 11, 2009 6:31 AM

illicedwepT said:

Hi I am new here just here to say hi and wondering if there is anyone here who loves Tokio Hotel because I do.

xxx

Cindy

# July 14, 2009 4:12 AM

Trodapraica said:

hey,

just wanted to say hi, i'm new to this little forum :)

# July 16, 2009 2:47 AM

EnfokalankNok said:

I couldn’t surmise from word go paragraph of you article, but I speculation I fitting fulness to brake more resources apropos this, because it sounds most intriguing

my place:

www.sharepointu.com/.../default.aspx

Buy

# July 28, 2009 2:12 AM

EnfokalankNok said:

entertain enjoyed your position rather much and benefited from the word. as a result of You….

<a href="www.wikio.com/.../balbbes">download movies</a>

# July 29, 2009 12:55 AM

JermayneSai said:

NeronChedsada

# July 29, 2009 3:26 AM

YankeeRaztush said:

ShelleyHarding

# July 29, 2009 8:04 PM

Beammobbife said:

hey guys, I would like to get a [url=http://www.psphacks.com/]PSP slim[/url] so now I'm selling my old [url=http://www.psphacks.com/]psp fat[/url]. it has a blue faceplate([url=http://www.psphacks.com/]Sony PSP[/url] logo, etc.)  I would say it's in good condition with the normal light scuffs on the back.

# July 30, 2009 4:07 PM

prada shoes said:

I love this website.

# August 1, 2009 8:33 PM

deepakgatesc said:

# August 3, 2009 9:04 AM

KlsioLins said:

afg-1

# August 5, 2009 2:26 AM

georgesovereign said:

We renovate houses In MD.

Interior / exterior  remodelings,

reasonable prices,license,

references,photos,estimates,

also buy houses to renovate::

http://www.renewhouse4u.com.

Thanks

# August 8, 2009 12:16 AM

MikeInger said:

ghgh

# August 9, 2009 12:59 AM

Win7 Default Program setting problem .rar said:

Pingback from  Win7 Default Program setting problem .rar

# November 29, 2009 11:38 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: