1
A
回答
0
我發現了一個簡單的方法,通過vb.net文件相關聯(從CodeProject,鏈接:http://www.codeproject.com/Articles/18594/File-Association-in-VB-NET)
的代碼是:
My.Computer.Registry.ClassesRoot.CreateSubKey(".rtf").SetValue("", "Rich Text File", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("Rich Text File\shell\open\command").SetValue("", Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
+1
基本上和我發佈的內容一樣,但是在一行中(所以當某些事情發生時很難找到錯誤出錯)。如果不使用'SHChangeNotify',您可能必須重新啓動機器才能使更改生效 –
3
這種事情通常是由處理器專用的安裝程序,但使用.NET代碼,雖然你的程序運行的時候會需要管理員權限,你可以做到這一點...
看一看在VB這個完整的示例.NET:
http://www.devx.com/vb2themax/Tip/19554?type=kbArticle&trk=MSCP
感謝馬可Bellinaso的代碼。下面是逐字代碼,以防止腐爛鏈接:
<System.Runtime.InteropServices.DllImport("shell32.dll")> Shared Sub _
SHChangeNotify(ByVal wEventId As Integer, ByVal uFlags As Integer, _
ByVal dwItem1 As Integer, ByVal dwItem2 As Integer)
End Sub
' Create the new file association
'
' Extension is the extension to be registered (eg ".cad"
' ClassName is the name of the associated class (eg "CADDoc")
' Description is the textual description (eg "CAD Document"
' ExeProgram is the app that manages that extension (eg "c:\Cad\MyCad.exe")
Function CreateFileAssociation(ByVal extension As String, _
ByVal className As String, ByVal description As String, _
ByVal exeProgram As String) As Boolean
Const SHCNE_ASSOCCHANGED = &H8000000
Const SHCNF_IDLIST = 0
' ensure that there is a leading dot
If extension.Substring(0, 1) <> "." Then
extension = "." & extension
End If
Dim key1, key2, key3 As Microsoft.Win32.RegistryKey
Try
' create a value for this key that contains the classname
key1 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension)
key1.SetValue("", className)
' create a new key for the Class name
key2 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className)
key2.SetValue("", description)
' associate the program to open the files with this extension
key3 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(className & _
"\Shell\Open\Command")
key3.SetValue("", exeProgram & " ""%1""")
Catch e As Exception
Return False
Finally
If Not key1 Is Nothing Then key1.Close()
If Not key2 Is Nothing Then key2.Close()
If Not key3 Is Nothing Then key3.Close()
End Try
' notify Windows that file associations have changed
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0)
Return True
End Function
相關問題
- 1. 在VB.NET中創建文件關聯?
- 2. VB.net從CSV文件創建聯繫人
- 3. 創建關聯使用JPA
- 4. 使用vb.net創建文件夾
- 5. 在dbml文件中創建關聯?
- 6. 關聯創建事件
- 7. 使用xdgutils在Ubuntu中創建文件關聯圖標
- 8. 用VB.NET創建一個文本文件
- 9. VB.NET - 創建從文件
- 10. 用matplotlib創建關聯圖
- 11. 使用has_many後沒有創建關聯
- 12. 使用MySQL Workbench創建多態關聯
- 13. 使用休息創建實體關聯
- 14. Rails:使用遷移來創建關聯
- 15. 在CakePHP中使用其他關聯創建關聯3
- 16. 如何用VB.Net創建文件夾?
- 17. 使用VB.NET創建PDF文檔?
- 18. 用VB.Net創建VS2008插件?
- 19. 使用VB.NET創建ODBC DSN
- 20. 創建使用OCR和vb.net
- 21. 如何創建創建關聯數組?
- 22. 創建記錄後創建關聯
- 23. 如何使用ClickOnce在WPF應用程序中創建文件關聯?
- 24. FactoryGirl沒有創建關聯
- 25. :如何創建關聯?
- 26. create_association_name不會創建關聯
- 27. ORM - 創建關聯對象
- 28. 創建組關聯數組
- 29. GRPC。如何創建關聯?
- 30. 創建多級關聯rails
您使用的是什麼安裝程序? –
我正在用vb.net代碼創建我自己的安裝程序。 – Benjli