[英]File Association for my own Visual Basic application
我制作了可以在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
但我想将程序默认为该扩展名,并为这些文件设置图标。 是否可以通过Visual Basic实现?
您的代码看起来像这样...
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)
这是有关如何在VB .NET中执行此操作的完整示例。 如上文所述,您需要更改一些注册表设置。
https://www.codeproject.com/Articles/18594/File-Association-in-VB-NET
快速浏览一下您的代码, GetCommandLineArgs(1)
需要更改为GetCommandLineArgs(0)
才能正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.