2017-07-14 54 views
1

我在我的应用程序,它可以读取在Visual Basic 2017文件关联为自己的Visual Basic应用程序

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发生?

+0

这是你会在Windows(或者你正在使用的任何操作系统)中做的事情 – Magnus

+0

也许类似于:https://stackoverflow.com/questions/2681878/associate-file-extension-with-application – Magnus

+0

这就是C#和我不明白 –

回答

1

您的代码将是这个样子......

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) 
+0

它什么也没做。我希望我的程序默认打开'.myOwnExt',它只在我通过文件打开时显示错误 –

相关问题