1

I made my application that can read some specific extension on load in Visual Basic 2017.

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Environment.GetCommandLineArgs(1).ToString = My.Application.Info.DirectoryPath.ToString + "\" + My.Application.Info.AssemblyName + ".exe" Then

        Else
            If System.IO.Path.GetExtension(Environment.GetCommandLineArgs(1)) = ".myOwnExt" Then
                Dim fileReader As String
                fileReader = My.Computer.FileSystem.ReadAllText(Environment.GetCommandLineArgs(1).ToString)
                MsgBox(fileReader)
            End If
        End If
    End Sub

But I want to make my program default for that extension and I want to set my icon for those files. Is it possible to make it happen with Visual Basic?

Djordje Vujicic
  • 414
  • 5
  • 20

2 Answers2

1

Your code would look something like this...

My.Computer.Registry.ClassesRoot.CreateSubKey(".myOwnExt").SetValue("", _
          "myOwnExt", Microsoft.Win32.RegistryValueKind.String)     
My.Computer.Registry.ClassesRoot.CreateSubKey("MyProgramName\shell\open\command").SetValue("", _
          Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
DWRoelands
  • 4,878
  • 4
  • 29
  • 42
  • It doesn't do anything. I want my program to be default for opening `.myOwnExt` It only shows error when I open it through file – Djordje Vujicic Jul 14 '17 at 13:22
1

Here is a full example on how to do this in VB .NET. Like mentioned above you need to change some registry settings.

https://www.codeproject.com/Articles/18594/File-Association-in-VB-NET

On a quick glance at your code GetCommandLineArgs(1) needs to be changed to GetCommandLineArgs(0) to get this working.

Valderann
  • 805
  • 12
  • 30