Solved

Associating a file extension to an application.

Posted on 1998-06-02
7
186 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
[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
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
ID: 1462297
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
ID: 1462298
kamall:

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

Expert Comment

by:kamall
ID: 1462299
Thats right ksm.
0
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!

 

Author Comment

by:ksm
ID: 1462300
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
ID: 1462301
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
ID: 1462302
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
ID: 1462303
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

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 105
Adding to a VBA? 6 93
How does CurrentUser work? 10 44
converting visio 2010 to powerpoint 2010  - formatting issues 5 123
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 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