Reputation: 412
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?
Upvotes: 1
Views: 1255
Reputation: 835
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.
Upvotes: 1
Reputation: 4940
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)
Upvotes: 1