Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 我自己的Visual Basic应用程序的文件关联_Vb.net_Visual Studio_File_Visual Studio 2010_Registry - Fatal编程技术网

Vb.net 我自己的Visual Basic应用程序的文件关联

Vb.net 我自己的Visual Basic应用程序的文件关联,vb.net,visual-studio,file,visual-studio-2010,registry,Vb.net,Visual Studio,File,Visual Studio 2010,Registry,我制作的应用程序可以在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.Assemb

我制作的应用程序可以在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中执行此操作的完整示例。就像上面提到的,您需要更改一些注册表设置


快速浏览代码时,需要将
GetCommandLineArgs(1)
更改为
GetCommandLineArgs(0)
,以使其正常工作

这是你在Windows(或任何你正在使用的操作系统)中会做的事情,也许是这样的:那是C#,我不明白,只是把它贯穿到你要寻找的术语是文件关联。通过安装程序或手动方式,使用.REG文件以代码的形式创建它们。无需在代码中检查扩展名-当用户打开具有正确注册的扩展名的文件时,Windows将启动您的应用程序,并将while文件名作为命令行参数发送到上。它不会执行任何操作。我希望我的程序默认打开
。myOwnExt
它只在通过文件打开时显示错误