Solved

How do I register a file type as part of my InstallShield Express Professional installation?

Posted on 1998-09-13
2
367 Views
Last Modified: 2013-11-14
I have written a program in VB 4 which allows the creation and editing of .rev files which are unique to my program.  I'm using InstallShield Express Professional V. 1.11a (*NOT* the setup program that comes with VB) to create the setup which provides the install/uninstall facilities for my end users.

What I want to do is make the InstallShield Express Professional setup program (*NOT* the actual program I have wrote) automatically register/unregister the .rev type, so that when a .rev file is viewed in Explorer etc., it appears as an icon I have specified.  Double clicking a .rev file should then automatically launch my program so the file can be edited, just like clicking on a .txt file will launch Notepad..

Thanks for your help.
0
Comment
Question by:Richard2000
2 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 50 total points
ID: 1434620
Simply tell installshield to add registry entries to resemble the following:

HKEY_CLASSES_ROOT
   .rev                      Default - "RevFile"
   RevFile
      DefaultIcon            Default - "c:\mypath\MyFile.exe,0"
      shell
         open
            command          Default - "c:\mypath\MyFile.exe"

That will cause windows to recognize your extension and start your program when it is double clicked.
     

0
 
LVL 14

Expert Comment

by:waty
ID: 1434621
Use this code to register your file extension :

Option Explicit

Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003

Private Const ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_OUTOFMEMORY = 6
Private Const ERROR_INVALID_PARAMETER = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
Private Const ERROR_NO_MORE_ITEMS = 259

Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_OPTION_NON_VOLATILE = 0

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long

Public Sub CreateAssociation(sExtension As String, sAppName As String, sFilePath As String)

   Dim sPath As String

   'File Associations begin with a listing
   'of the default extension under HKEY_CLASSES_ROOT.
   'So the first step is to create that
   'root extension item
   CreateNewKey "." & sExtension, HKEY_CLASSES_ROOT

   'To the extension just added, add a
   'subitem where the registry will look for
   'commands relating to the .xxx extension
   '("MyApp.Document"). Its type is String (REG_SZ)
   SetKeyValue "." & sExtension, "", sAppName & ".Document", REG_SZ

   'Create the 'MyApp.Document' item under
   'HKEY_CLASSES_ROOT. This is where you'll put
   'the command line to execute or other shell
   'statements necessary.
   CreateNewKey sAppName & ".Document\shell\open\command", HKEY_CLASSES_ROOT

   'Set its default item to "MyApp Document".
   'This is what is displayed in Explorer against
   'for files with a xxx extension. Its type is
   'String (REG_SZ)
   SetKeyValue sAppName & ".Document", "", sAppName & " Document", REG_SZ

   'Finally, add the path to myapp.exe
   'Remember to add %1 as the final command
   'parameter to assure the app opens the passed
   'command line item.
   '(results in '"c:\LongPathname\Myapp.exe %1")
   'Again, its type is string.
   sPath = sFilePath & " %1"
   SetKeyValue sAppName & ".Document\shell\open\command", "", sPath, REG_SZ

End Sub

Public Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long

   Dim nValue As Long
   Dim sValue As String

   Select Case lType
      Case REG_SZ
         sValue = vValue & Chr$(0)
         SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))

      Case REG_DWORD
         nValue = vValue
         SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, nValue, 4)

   End Select

End Function


Public Sub CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)

   'handle to the new key
   Dim hKey As Long

   'result of the RegCreateKeyEx function
   Dim r As Long

   r = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hKey, r)

   Call RegCloseKey(hKey)

End Sub

Public Sub SetKeyValue(sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)

   'result of the SetValueEx function
   Dim r As Long

   'handle of opened key
   Dim hKey As Long

   'open the specified key
   r = RegOpenKeyEx(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_ALL_ACCESS, hKey)

   r = SetValueEx(hKey, sValueName, lValueType, vValueSetting)

   Call RegCloseKey(hKey)

End Sub


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vmware vcenter install/upgrade issue 6 226
Set email body to html using vbscript 6 69
Microsoft volume license for installation 11 47
hp envy 4500 driver installation problem 5 74
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question