Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/fileassociations/fa_intro.asp

 

http://www.windowsitlibrary.com/Content/368/07/2.html?Ad=1&

 

Imports Microsoft.Win32;

 

Dim regClassRoot as RegistryKey = Registry.ClassesRoot;

regClassRoot.CreateSubKey("applicationName");

regClassRoot.SetValue("whavever", "applicationpath");

 

 

Create two trees similar to the ones on the msdn page.

The result will be that you will be creating a key to identify what program opens

the file type and a key to describe the application and it's run path.

 

It would be a better idea to use the Windows Installer to create the registry keys and register the file extension.

 

Marble_eater, for being such a big proponent of 'googling' you sure do give crappy links.

  • Leaders
Posted

don't know about crappy links :rolleyes: the 2nd link in the list on that google search happens to be one of the best VB code sites on the net, nearly all of it may be pre - .NET, but just about all of that can be modded to work in .NET

 

this section of code ....

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Copyright ©1996-2005 VBnet, Randy Birch, All Rights Reserved.

' Some pages may also contain other copyrights by the author.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Distribution: You can freely use this code in your own

' applications, but you may not reproduce

' or publish this code on any web site,

' online service, or distribute as source

' on any media without express permission.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Sub CreateAssociation()

 

Dim sPath As String

 

'File Associations begin with a listing

'of the default extension under HKEY_CLASSES_ROOT.

'So the first step is to create that

'root extension item

CreateNewKey ".xxx", HKEY_CLASSES_ROOT

 

 

'To the extension just added, add a

'subitem where the registry will look for

'commands relating to the .xxx extension

'("MyApp.Document"). Its type is String (REG_SZ)

SetKeyValue ".xxx", "", "MyApp.Document", REG_SZ

 

 

'Create the 'MyApp.Document' item under

'HKEY_CLASSES_ROOT. This is where you'll put

'the command line to execute or other shell

'statements necessary.

CreateNewKey "MyApp.Document\shell\open\command", HKEY_CLASSES_ROOT

 

 

'Set its default item to "MyApp Document".

'This is what is displayed in Explorer against

'for files with a xxx extension. Its type is

'String (REG_SZ)

SetKeyValue "MyApp.Document", "", "MyApp Document", REG_SZ

 

 

'Finally, add the path to myapp.exe

'Remember to add %1 as the final command

'parameter to assure the app opens the passed

'command line item.

'(results in '"c:\LongPathname\Myapp.exe %1")

'Again, its type is string.

sPath = "c:\LongPathname\Myapp.exe %1"

SetKeyValue "MyApp.Document\shell\open\command", "", sPath, REG_SZ

 

'All done

MsgBox "The file association has been made!"

 

End Sub

gives you a perfect insight into which key to create / set

the shell\open\command section of RegKey is the part that you need to set the Default item of, using as Diesel said the Microsoft.Win32.Registry class.

 

BTW: Diesel , you seem to be mixing and matching your VB & C# in that code ;) by the look of those ; ; ;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...