Prev: how to connect from vbs code to local MS Access database
Next: Error 30366 in VB code behind Visual Studio 2005 project
From: Leo on 7 Apr 2010 07:59 I would like to allow my users to register my apps file extension from within the app. I have managed to register the extension but the description isn't being shown in explorer on xp or 7, I can not also get the icon to display. Below is the code I found on the internet: Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long Private Const ERROR_SUCCESS = 0& Private Const ERROR_BADDB = 1009& Private Const ERROR_BADKEY = 1010& Private Const ERROR_CANTOPEN = 1011& Private Const ERROR_CANTREAD = 1012& Private Const ERROR_CANTWRITE = 1013& Private Const ERROR_OUTOFMEMORY = 14& Private Const ERROR_INVALID_PARAMETER = 87 ' dderror Private Const ERROR_ACCESS_DENIED = 5& Private Const HKEY_CLASSES_ROOT = &H80000000 Private Const MAX_PATH = 260& Private Const REG_SZ = 1 'USAGE: RegisterAsFileType "c:\program files\sdp.exe", ".sdr", "sdrfile", "SDP Data File", 0 Public Function RegisterAsFileType(ByVal sAppPath As String, ByVal sExtension As String, _ ByVal sExtHandle As String, ByVal sFileDescription As String, _ ByVal iIconNumber As Integer) As Integer 'IN: sAppPath - Full path to the Application, including the File Name ' sExtension - the File extension to regsiter, eg .mdb ' sExthandle - the handle for the extension to enter in the App section ' sFileDescription - Description of the File Type ' iIconNumber - the icon offset to use from the executable 'PURPOSE: Registers a passed in extension as a file type and associates it with a ' passed in Executable sKeyName = sExtension sKeyValue = sExtHandle ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) sKeyName = sExtHandle sKeyValue = sFileDescription ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) sKeyName = sExtHandle & "\shell\open\command" sKeyValue = sAppPath & " %1" ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) sKeyName = sExtHandle & "\DefaultIcon" sKeyValue = sAppPath & ",0" ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) End Function
From: C. Kevin Provance on 7 Apr 2010 08:47 FWIW, I have found that handling this kind of task is better suited for the apps installer. -- 2025 If you do not believe in time travel, your beliefs are about to be tempered. http://www.facebook.com/group.php?gid=43606237254 "Leo" <Leo(a)discussions.microsoft.com> wrote in message news:E9042321-86B4-4CEE-9963-E0F7C78A65F8(a)microsoft.com... :I would like to allow my users to register my apps file extension from within : the app. I have managed to register the extension but the description isn't : being shown in explorer on xp or 7, I can not also get the icon to display. : : Below is the code I found on the internet: : : Private Declare Function RegCreateKey Lib "advapi32.dll" Alias : "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As : Long) As Long : Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" : (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal : lpData As String, ByVal cbData As Long) As Long : : Private Const ERROR_SUCCESS = 0& : Private Const ERROR_BADDB = 1009& : Private Const ERROR_BADKEY = 1010& : Private Const ERROR_CANTOPEN = 1011& : Private Const ERROR_CANTREAD = 1012& : Private Const ERROR_CANTWRITE = 1013& : Private Const ERROR_OUTOFMEMORY = 14& : Private Const ERROR_INVALID_PARAMETER = 87 ' dderror : Private Const ERROR_ACCESS_DENIED = 5& : : Private Const HKEY_CLASSES_ROOT = &H80000000 : Private Const MAX_PATH = 260& : Private Const REG_SZ = 1 : : 'USAGE: RegisterAsFileType "c:\program files\sdp.exe", ".sdr", "sdrfile", : "SDP Data File", 0 : : Public Function RegisterAsFileType(ByVal sAppPath As String, ByVal : sExtension As String, _ : ByVal sExtHandle As String, ByVal sFileDescription As String, _ : ByVal iIconNumber As Integer) As Integer : 'IN: sAppPath - Full path to the Application, including the : File Name : ' sExtension - the File extension to regsiter, eg .mdb : ' sExthandle - the handle for the extension to enter in the : App section : ' sFileDescription - Description of the File Type : ' iIconNumber - the icon offset to use from the executable : 'PURPOSE: Registers a passed in extension as a file type and associates it : with a : ' passed in Executable : : sKeyName = sExtension : sKeyValue = sExtHandle : ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) : ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) : : sKeyName = sExtHandle : sKeyValue = sFileDescription : ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) : ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) : : sKeyName = sExtHandle & "\shell\open\command" : sKeyValue = sAppPath & " %1" : ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) : ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) : : sKeyName = sExtHandle & "\DefaultIcon" : sKeyValue = sAppPath & ",0" : ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&) : ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&) : : End Function :
From: Mayayana on 7 Apr 2010 09:40
Your code is outdated and seems to be partial. (I hope it's partial, since you didn't close the key. :) See here for Randy Birch's sample of exactly what you want to do: http://vbnet.mvps.org/code/reg/association.htm Also watch out for permission issues. As Kevin implied, if you don't create the keys/values during install then the person may not have sifficient permission on Vista/7 (and in some cases on XP). |