Set Registry key to make program a default

Robert Homes

Member
Joined
Nov 16, 2023
Messages
11
Programming Experience
5-10
How to set registry key to make program a default for a particular file type. My program works with .JPG files. I'd like to set the registry to treat my program as the default for such files.
 
Not yet., But I expect to have one soon. Actually, I'm still developing the program and its not quite finished. I'm must working on this to get ready for when I'm done. I have someone helping me with the installer aspect. I didn't realize that the installer could probably set the default I'm looking for. Thanks for that insight.
 
It is also possible to open Default Apps settings where user can choose:
VB.NET:
Process.Start(New ProcessStartInfo("ms-settings:defaultapps") With {.UseShellExecute = True})
 
This is another way, but JohnH gave you the fastest approach.
Setting Your VB.NET Application as the Default for Image Files:
Imports Microsoft.Win32

Module Module1
   Private Sub Main()
        Dim appName As String = "YourAppName"
        Dim appPath As String = "C:\Path\To\YourApp.exe"

        ' Set the default application for .jpg files
        SetDefaultApp(".jpg", appName, appPath)
        ' Set the default application for .png files
        SetDefaultApp(".png", appName, appPath)
        ' Set the default application for .bmp files
        SetDefaultApp(".bmp", appName, appPath)
    End Sub

   Private Sub SetDefaultApp(extension As String, appName As String, appPath As String)
        Dim key As RegistryKey = Registry.ClassesRoot.CreateSubKey(extension)
        key.SetValue("", appName)

        Dim appKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(appName)
        appKey.SetValue("", "Image File")
        appKey.CreateSubKey("shell\open\command").SetValue("", """" & appPath & """ ""%1""")
    End Sub
End Module
 
Back
Top