question on windows registry

baappi

New member
Joined
Dec 3, 2007
Messages
4
Programming Experience
Beginner
Hi experts,

I am rather a newbie to .NET .
My problem is : how can I identify the default application associacted with a file to open it up (just like Windows OS detects it and opens it up when we double click a file) in VB.NET .

Say, I have a .xyz file (might be a simple text document) in my machine and 3 to 4 application could open it up .
But I need to identify
1. the default program set to open it up
2. the location of the default program where it is installed

Any idea ?? Do I need to read egistry stuffs ?? Any help is greatly appriciated .

Thanks In Advance
Baappi
 
In HKEY_Classes_Root there is a .xyz key. When viewing this in Regedit you see the "(Default)" string name-value has a reference in the value to the application handler. "(Default)" is just RegEdit applications way of denoting the default name-value pair, the name is actually an empty string.

For example the .sln file extension is at my machine registered to "VisualStudio.Launcher.sln", this is also a key in classes_root where (Default) value is the name (Microsoft Visual Studio Solution) and you check the "Shell\Open\Command" subkey for path, in this case that (Default) has this value:
"C:\Program Files\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe" "%1"
Sample code that reads these value into name and path variables:
VB.NET:
Dim reg As Microsoft.Win32.RegistryKey = My.Computer.Registry.ClassesRoot.OpenSubKey(".sln")
Dim appref As String = CStr(reg.GetValue(""))
reg.Close()

reg = My.Computer.Registry.ClassesRoot.OpenSubKey(appref)
Dim name As String = CStr(reg.GetValue(""))
reg.Close()

reg = My.Computer.Registry.ClassesRoot.OpenSubKey(appref & "\Shell\Open\Command")
Dim path As String = CStr(reg.GetValue(""))
reg.Close()
Also consider the information in classes_root documentation if user/machine settings makes a difference.
 
Back
Top