Solved

Associating file types with a .exe

Posted on 1998-06-24
7
250 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now