Solved

Associating file types with a .exe

Posted on 1998-06-24
7
271 Views
Last Modified: 2010-05-03
How do you associate a filetype to a certain .exe file made using vb and a certain icon?  What do I have to add to the setup program?
0
Comment
Question by:wsanchez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 1464148
wsanchez,

  Basically to associate a extension with your application, you must have appropriate information in the Registry. For example, your application name test.exe and stay in folder C:\temp, the extension to associate is .aaa. Then, in your registry, these key must existed:
(HKCR = HKEY_CLASSES_ROOT)

[HKCR\.aaa]
@Defaule="aaafile"

[HKCR\aaafile\shell\open\command]
@Default="C:\temp\test.exe %1"

' And the default icon for the file with .aaa
[HKCR\aaafile\DefaultIcon]
@Default="C:\temp\test.exe,1"   (this mean first icon contain in                                  test.exe)


Use regedit.exe to open the registry and looking for HKCR\.htm, HKCR\htmlfiles and you will know how to do it.

For setting this info, you must modify your setup wizard program, to add stuff for insert info into registry in the startup of setup.

For reference, look for MS KB Q185453. I think the PAQ also got some similiar question.

Regards
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464149
wsanchez,

  Basically to associate a extension with your application, you must have appropriate information in the Registry. For example, your application name test.exe and stay in folder C:\temp, the extension to associate is .aaa. Then, in your registry, these key must existed:
(HKCR = HKEY_CLASSES_ROOT)

[HKCR\.aaa]
@Defaule="aaafile"

[HKCR\aaafile\shell\open\command]
@Default="C:\temp\test.exe %1"

' And the default icon for the file with .aaa
[HKCR\aaafile\DefaultIcon]
@Default="C:\temp\test.exe,1"   (this mean first icon contain in                                  test.exe)


Use regedit.exe to open the registry and looking for HKCR\.htm, HKCR\htmlfiles and you will know how to do it.

For setting this info, you must modify your setup wizard program, to add stuff for insert info into registry in the startup of setup.

For reference, look for MS KB Q185453. I think the PAQ also got some similiar question.

Regards
0
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
ID: 1464150
You will put this code in your EXE and execute it only the first time your program runs. You can determine if it is the first time by creating a simple INI file on the user machine.

The following code will put an association to .xyz to the file XYZ:

    In your declarations section:
    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

    ' Return codes from Registration functions.
    Const ERROR_SUCCESS = 0&
    Const ERROR_BADDB = 1&
    Const ERROR_BADKEY = 2&
    Const ERROR_CANTOPEN = 3&
    Const ERROR_CANTREAD = 4&
    Const ERROR_CANTWRITE = 5&
    Const ERROR_OUTOFMEMORY = 6&
    Const ERROR_INVALID_PARAMETER = 7&
    Const ERROR_ACCESS_DENIED = 8&

    Const HKEY_CLASSES_ROOT = &H80000000
    Const MAX_PATH = 256&
    Const REG_SZ = 1

    The code to write to the registry:
      Dim sKeyName As String   'Holds Key Name in registry.
      Dim sKeyValue As String  'Holds Key Value in registry.
      Dim ret&           'Holds error status if any from API calls.
      Dim lphKey&        'Holds created key handle from RegCreateKey.
       
      'This creates a Root entry called "XYZ".
      sKeyName = "XYZ"
      sKeyValue = "XYZ App"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
       
      'This creates a Root entry called .xyz associated with "XYZ".
      sKeyName = ".xyz"
      sKeyValue = "XYZ"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
       
      'This sets the command line for "XYZ".
      sKeyName = "XYZ"
      sKeyValue = "c:\XYZ\XYZ.exe %1"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH)

Regards
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:wsanchez
ID: 1464151
To kamall.  What do I write in the INI file? Sorry for asking but I'm quite new at this.  Also, what if the person who installs the software gives a different installation path during installation?  How would I reflect the path in the registry?
0
 
LVL 7

Expert Comment

by:kamall
ID: 1464152
wsanchez,
Sorry for the delay in reponding, but I didn't get e-mail notification of your comment. I saw your other question 'To kamall...' which led me here.
So, the solution to your question is very simple.
You can just create an empty INI file (or write anything you like) when your program runs for the first time, and put it in the application's directory. You can simply get the application directory using the App.Path
Now when your program runs, you simply check whether your INI file exists. If not, then it is the first time, otherwise it is not.
This will not cause you any problems if the user installs your application in any other directory name.
Regards
0
 

Author Comment

by:wsanchez
ID: 1464153
Thanks Kamall.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1464154
You are welcome wsanchez.
For any more questions, leave me a comment.
Best regards.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

695 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