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
Solved

Associating file types with a .exe

Posted on 1998-06-24
7
257 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

839 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