Dateierweiterung für eigenes Programm registrieren

    • VB6

    Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Alex2000.

      Dateierweiterung für eigenes Programm registrieren

      Hai !!!
      Du Programmierst ein Editor und hast eigene Datei erweiterung, und wenn du auf die Datei klickst soll deine Anwendung gestartet werden, kein Problem, hier ist die Code

      Visual Basic-Quellcode

      1. Option Explicit
      2. ' zun?chst alle ben?tigten API-Deklarationen
      3. Private Const HKEY_LOCAL_MACHINE = &H80000002
      4. Private Const KEY_ALL_ACCESS = &H3F
      5. Private Const KEY_SET_VALUE = &H2
      6. Private Const KEY_CREATE_SUB_KEY = &H4
      7. Private Const REG_PRIMARY_KEY = "Software\Classes\"
      8. Private Const REG_SHELL_KEY = "Shell\"
      9. Private Const REG_SHELL_OPEN_KEY = "Open\"
      10. Private Const REG_SHELL_OPEN_COMMAND_KEY = "Command"
      11. Private Const REG_SZ = 1
      12. Private Const REG_OPTION_NON_VOLATILE = 0
      13. Private Const ERROR_SUCCESS = 0&
      14. Private Type SECURITY_ATTRIBUTES
      15. nLength As Long
      16. lpSecurityDescriptor As Long
      17. bInheritHandle As Boolean
      18. End Type
      19. Private Declare Function RegCloseKey Lib "advapi32.dll" _
      20. (ByVal hKey As Long) As Long
      21. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
      22. Alias "RegOpenKeyExA" (ByVal hKey As Long, _
      23. ByVal lpSubKey As String, ByVal ulOptions As Long, _
      24. ByVal samDesired As Long, phkResult As Long) As Long
      25. Private Declare Function RegCreateKeyEx Lib "advapi32.dll" _
      26. Alias "RegCreateKeyExA" (ByVal hKey As Long, _
      27. ByVal lpSubKey As String, ByVal Reserved As Long, _
      28. ByVal lpClass As String, ByVal dwOptions As Long, _
      29. ByVal samDesired As Long, lpSecurityAttributes As _
      30. SECURITY_ATTRIBUTES, phkResult As Long, _
      31. lpdwDisposition As Long) As Long
      32. Private Declare Function RegSetValue Lib "advapi32.dll" _
      33. Alias "RegSetValueA" (ByVal hKey As Long, _
      34. ByVal lpSubKey As Any, ByVal dwType As Long, _
      35. ByVal lpData As String, ByVal cbData As Long) As Long
      36. Private Function OpenKey(lhKey As Long, SubKey As String, _
      37. ulOptions As Long) As Long
      38. Dim lhKeyOpen As Long
      39. Dim lResult As Long
      40. lhKeyOpen = 0
      41. lResult = RegOpenKeyEx(lhKey, SubKey, 0, ulOptions, _
      42. lhKeyOpen)
      43. If lResult <> ERROR_SUCCESS Then
      44. OpenKey = 0
      45. Else
      46. OpenKey = lhKeyOpen
      47. End If
      48. End Function
      49. Private Function CreateKey(lhKey As Long, SubKey As _
      50. String, NewSubKey As String) As Boolean
      51. Dim lhKeyOpen As Long
      52. Dim lhKeyNew As Long
      53. Dim lDisposition As Long
      54. Dim lResult As Long
      55. Dim Security As SECURITY_ATTRIBUTES
      56. lhKeyOpen = OpenKey(lhKey, SubKey, _
      57. KEY_CREATE_SUB_KEY)
      58. lResult = RegCreateKeyEx(lhKeyOpen, NewSubKey, 0, "", _
      59. REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, Security, _
      60. lhKeyNew, lDisposition)
      61. If lResult = ERROR_SUCCESS Then
      62. CreateKey = True
      63. RegCloseKey (lhKeyNew)
      64. Else
      65. CreateKey = False
      66. End If
      67. RegCloseKey (lhKeyOpen)
      68. End Function
      69. Private Function SetValue(lhKey As Long, SubKey As _
      70. String, sValue As String) As Boolean
      71. Dim lhKeyOpen As Long
      72. Dim lResult As Long
      73. Dim lTyp As Long
      74. Dim lByte As Long
      75. lByte = Len(sValue)
      76. lTyp = REG_SZ
      77. lhKeyOpen = OpenKey(lhKey, SubKey, KEY_SET_VALUE)
      78. lResult = RegSetValue(lhKey, SubKey, lTyp, sValue, _
      79. lByte)
      80. If lResult <> ERROR_SUCCESS Then
      81. SetValue = False
      82. Else
      83. SetValue = True
      84. RegCloseKey (lhKeyOpen)
      85. End If
      86. End Function
      87. ' Datei-Verkn?pfung in der Registry speichern
      88. ' Datei-Verkn?pfung in der Registry speichern
      89. ' sFileExt = Dateiendung (z.B. .txt)
      90. ' sFileDescr = Beschreibung (z.B. Textdokument)
      91. ' sAppID = Programm-Kennung (z.B. Mein Texteditor)
      92. ' sOpenCmd = vollst?ndiger Dateiname der Anwendung
      93. ' inkl. Parameter %1
      94. ' (z.B. App.Path & "\" & App.EXEName & ".exe %1"
      95. Public Function RegisterFile(sFileExt As String, _
      96. sFileDescr As String, sAppID As String, _
      97. sOpenCmd As String) As Boolean
      98. Dim hKey As Long
      99. Dim bSuccess As Boolean
      100. bSuccess = False
      101. hKey = HKEY_LOCAL_MACHINE
      102. ' File-Extension
      103. If CreateKey(hKey, REG_PRIMARY_KEY, sFileExt) Then
      104. If SetValue(hKey, REG_PRIMARY_KEY & sFileExt, _
      105. sAppID) Then
      106. ' AppID
      107. If CreateKey(hKey, REG_PRIMARY_KEY, sAppID) Then
      108. ' AppDescription
      109. If SetValue(hKey, REG_PRIMARY_KEY & sAppID, _
      110. sFileDescr) Then
      111. ' OpenCommand
      112. If CreateKey(hKey, REG_PRIMARY_KEY & sAppID, _
      113. REG_SHELL_KEY & REG_SHELL_OPEN_KEY & _
      114. REG_SHELL_OPEN_COMMAND_KEY) Then
      115. bSuccess = SetValue(hKey, REG_PRIMARY_KEY & _
      116. sAppID & "\" & REG_SHELL_KEY & _
      117. REG_SHELL_OPEN_KEY & _
      118. REG_SHELL_OPEN_COMMAND_KEY, sOpenCmd)
      119. End If
      120. End If
      121. End If
      122. End If
      123. End If
      124. RegisterFile = bSuccess
      125. End Function
      126. Beispiel
      127. ' .txt-Dateien registrieren
      128. RegisterFile ".txt", "Textdokument", "MeinTexteditor", _
      129. App.Path & "\" & App.EXEName & ".exe %1"





      Willst du für deine Eigene Datei erweiterung eigene Symbol, auch kein Problemm hier ist die Code

      Visual Basic-Quellcode

      1. Dim objSubKey As Microsoft.Win32.RegistryKey
      2. Dim objSubKey2 As Microsoft.Win32.RegistryKey
      3. Dim Wert As String = "Dein Name"
      4. Dim sKey As String = ".deine Endung"
      5. Dim sKey2 As String = ".deine Endung\ShellNew"
      6. Dim sEntry As String = "Content Type"
      7. Dim sValue As String = "text/plain"
      8. Dim sEntry2 As String = "PerceivedType"
      9. Dim sValue2 As String = "text"
      10. Dim sEntry3 As String = "Nullfile"
      11. objSubKey = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey)
      12. objSubKey.SetValue("", Wert)
      13. objSubKey.SetValue(sEntry, sValue)
      14. objSubKey.SetValue(sEntry2, sValue2)
      15. objSubKey2 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey2)
      16. objSubKey2.SetValue(sEntry3, "")
      17. Dim objSubKey3 As Microsoft.Win32.RegistryKey
      18. Dim sKey3 As String = "Dein Name"
      19. Dim sKey4 As String = "Dein Name\shell\open\command"
      20. Dim skey5 As String = "Dein Name\DefaultIcon"
      21. Dim sValue3 As String = "Dein Name"
      22. Dim objSubKey5 As Microsoft.Win32.RegistryKey
      23. Dim sValue5 As String = """" + My.Application.Info.DirectoryPath + "" + ""der Pfad der exe mit dem es geöffnet werden soll"" + " %1"
      24. Dim sValue6 As String = """" + My.Application.Info.DirectoryPath + "pfad zum icon.ico" + """"
      25. Dim objSubKey4 As Microsoft.Win32.RegistryKey
      26. objSubKey3 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey3)
      27. objSubKey3.SetValue("", sValue3)
      28. objSubKey4 = My.Computer.Registry.ClassesRoot.CreateSubKey(sKey4)
      29. objSubKey4.SetValue("", sValue5)
      30. objSubKey5 = My.Computer.Registry.ClassesRoot.CreateSubKey(skey5)
      31. objSubKey5.SetValue("", sValue6)



      Viel Spaß damit!! 8-) 8-) :thumbup:

      PS:BITTE KEINE ANTWORT !!!!

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Agent“ ()