Solved

Associating a file extension to an application.

Posted on 1998-06-02
7
195 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
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: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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

626 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