Solved

Associating a file extension to an application.

Posted on 1998-06-02
7
145 Views
Last Modified: 2010-05-03
In Visual Basic 5, how do you associate a file extension with an applications.  For example, how would I associate all *.ksm files with c:\myapp.exe ?

Thanx.
0
Comment
Question by:ksm
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
Comment Utility
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 = 1
    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 "XXX".
      sKeyName = "XXX"
      sKeyValue = "XXX App"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
       
      'This creates a Root entry called .XXX associated with "XXX".
      sKeyName = ".XXX"
      sKeyValue = "XXX"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
       
      'This sets the command line for "XXX".
      sKeyName = "XXX"
      sKeyValue = "c:\XXX\XXX.exe %1"
      ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
      ret& = RegSetValue&(lphKey&, "shell\open\command", REG_SZ, sKeyValue, MAX_PATH)

0
 

Author Comment

by:ksm
Comment Utility
kamall:

Do you have to make ALL 3 of those calls for each association?
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
Thats right ksm.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:ksm
Comment Utility
kamall:

Sorry to take so long to get back to you.

I just tried your example and it did not work.  I didn't get an error.  But I didn't see any new entries in the registry.  I ran the program, ensured that I was executing the calls above and nothing happened.  I'm using VB5 under WinNT.

Any suggestions?

Kevin
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
ksm,
Sorry for being away for a long time.
Regarding your comment, the code I gave you works fine in Windows 95 and it is tested. What I can guess is that the problem is the NT platform. There might be some different settings to take into considaration.

Regards
0
 

Author Comment

by:ksm
Comment Utility
The registry settings between Win95 and WinNT 4 are similar.  So the code should work in both OS's w/o having to modify it.  I got a hold of some more code and it seems to be working (got it from the MS KB site, of all places).  So your code should have worked.  I'll compare the MS stuff and the code you gave to me and get back to you shortly.

Thanks.
0
 
LVL 7

Expert Comment

by:kamall
Comment Utility
ksm,
Many people (me too) had problems so far on Windows NT with their developed applications that work perfectly on Windows 95. These problems do arise especially when using API calls. In most cases, no errors are reported by the NT OS.
I hope that the code you got will work, and I will be happy if you inform me of the results and show me the differences with the code I gave you.
I will be waiting for you.

Regards.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

728 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

9 Experts available now in Live!

Get 1:1 Help Now