Register a file extension

I would like to allow my users to register my apps file extension from within 
the app. I have managed to register the extension but the description isn't 
being shown in explorer on xp or 7, I can not also get the icon to display.

Below is the code I found on the internet:

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

Private Const ERROR_SUCCESS = 0&
Private Const ERROR_BADDB = 1009&
Private Const ERROR_BADKEY = 1010&
Private Const ERROR_CANTOPEN = 1011&
Private Const ERROR_CANTREAD = 1012&
Private Const ERROR_CANTWRITE = 1013&
Private Const ERROR_OUTOFMEMORY = 14&
Private Const ERROR_INVALID_PARAMETER = 87 '  dderror
Private Const ERROR_ACCESS_DENIED = 5&

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const MAX_PATH = 260&
Private Const REG_SZ = 1

'USAGE: RegisterAsFileType "c:\program files\sdp.exe", ".sdr", "sdrfile", 
"SDP Data File", 0

Public Function RegisterAsFileType(ByVal sAppPath As String, ByVal 
sExtension As String, _
    ByVal sExtHandle As String, ByVal sFileDescription As String, _
    ByVal iIconNumber As Integer) As Integer
'IN:    sAppPath            - Full path to the Application, including the 
File Name
'       sExtension          - the File extension to regsiter, eg .mdb
'       sExthandle          - the handle for the extension to enter in the 
App section
'       sFileDescription    - Description of the File Type
'       iIconNumber         - the icon offset to use from the executable
'PURPOSE:   Registers a passed in extension as a file type and associates it 
with a
'           passed in Executable

          sKeyName = sExtension
          sKeyValue = sExtHandle
          ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
          ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

          sKeyName = sExtHandle
          sKeyValue = sFileDescription
          ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
          ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

          sKeyName = sExtHandle & "\shell\open\command"
          sKeyValue = sAppPath & " %1"
          ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
          ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

          sKeyName = sExtHandle & "\DefaultIcon"
          sKeyValue = sAppPath & ",0"
          ret& = RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
          ret& = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)

End Function

0
Utf
4/7/2010 11:59:08 AM
vb.general.discussion 1016 articles. 0 followers. Follow

2 Replies
3010 Views

Similar Articles

[PageSpeed] 54

FWIW, I have found that handling this kind of task is better suited for =
the apps installer.

--=20
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=3D43606237254
"Leo" <Leo@discussions.microsoft.com> wrote in message =
news:E9042321-86B4-4CEE-9963-E0F7C78A65F8@microsoft.com...
:I would like to allow my users to register my apps file extension from =
within=20
: the app. I have managed to register the extension but the description =
isn't=20
: being shown in explorer on xp or 7, I can not also get the icon to =
display.
:=20
: Below is the code I found on the internet:
:=20
: Private Declare Function RegCreateKey Lib "advapi32.dll" Alias=20
: "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, =
phkResult As=20
: Long) As Long
: Private Declare Function RegSetValue Lib "advapi32.dll" Alias =
"RegSetValueA"=20
: (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, =
ByVal=20
: lpData As String, ByVal cbData As Long) As Long
:=20
: Private Const ERROR_SUCCESS =3D 0&
: Private Const ERROR_BADDB =3D 1009&
: Private Const ERROR_BADKEY =3D 1010&
: Private Const ERROR_CANTOPEN =3D 1011&
: Private Const ERROR_CANTREAD =3D 1012&
: Private Const ERROR_CANTWRITE =3D 1013&
: Private Const ERROR_OUTOFMEMORY =3D 14&
: Private Const ERROR_INVALID_PARAMETER =3D 87 '  dderror
: Private Const ERROR_ACCESS_DENIED =3D 5&
:=20
: Private Const HKEY_CLASSES_ROOT =3D &H80000000
: Private Const MAX_PATH =3D 260&
: Private Const REG_SZ =3D 1
:=20
: 'USAGE: RegisterAsFileType "c:\program files\sdp.exe", ".sdr", =
"sdrfile",=20
: "SDP Data File", 0
:=20
: Public Function RegisterAsFileType(ByVal sAppPath As String, ByVal=20
: sExtension As String, _
:    ByVal sExtHandle As String, ByVal sFileDescription As String, _
:    ByVal iIconNumber As Integer) As Integer
: 'IN:    sAppPath            - Full path to the Application, including =
the=20
: File Name
: '       sExtension          - the File extension to regsiter, eg .mdb
: '       sExthandle          - the handle for the extension to enter in =
the=20
: App section
: '       sFileDescription    - Description of the File Type
: '       iIconNumber         - the icon offset to use from the =
executable
: 'PURPOSE:   Registers a passed in extension as a file type and =
associates it=20
: with a
: '           passed in Executable
:=20
:          sKeyName =3D sExtension
:          sKeyValue =3D sExtHandle
:          ret& =3D RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
:          ret& =3D RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
:=20
:          sKeyName =3D sExtHandle
:          sKeyValue =3D sFileDescription
:          ret& =3D RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
:          ret& =3D RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
:=20
:          sKeyName =3D sExtHandle & "\shell\open\command"
:          sKeyValue =3D sAppPath & " %1"
:          ret& =3D RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
:          ret& =3D RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
:=20
:          sKeyName =3D sExtHandle & "\DefaultIcon"
:          sKeyValue =3D sAppPath & ",0"
:          ret& =3D RegCreateKey&(HKEY_CLASSES_ROOT, sKeyName, lphKey&)
:          ret& =3D RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)
:=20
: End Function
:
0
C
4/7/2010 12:47:13 PM
Your code is outdated and seems to be partial.
(I hope it's partial, since you didn't close the key. :)

  See here for Randy Birch's sample of exactly
what you want to do:

http://vbnet.mvps.org/code/reg/association.htm

  Also watch out for permission issues. As Kevin
implied, if you don't create the keys/values during
install then the person may not have sifficient
permission on Vista/7 (and in some cases on XP).


0
Mayayana
4/7/2010 1:40:40 PM
Reply:

Similar Artilces:

How can I remove an invalid path for an Access file from a pivot #2
I have an excel pivot table that uses Access as the data source, the file is on the network drive "m" at work. Does anyone know how to change the path of the Access file? The Access file is now on my C drive at home and it won't let me change the path. If you are in Excel, can't you simply goto: Data | Pivot Tables. Click the "get external data" toggle and then follow the prompts to browse for your file? Roger "CLASSC" wrote: > I have an excel pivot table that uses Access as the data source, the file is > on the network drive "m&quo...

Classification on the register
Noone wanted to answer my previous question about classifications, but I wil ask another one anyways :). I created a classification "Employee" to track which employee takes the money out of the petty cash (I thought of using payees, but I would sometimes like to track to whom actually the money as going as a payee). Is there any way to show the classification on the register so that I can quickly see who tooke the money? Thanks. I don't know squat about Invoice or the Business version. (Nor do most regular posters here who do not use the Business version either.) But I can t...

loaded office pro 07 1st cd & registed what about 2nd cd?
only promped for one cd ?????????????? I haven't loaded office from the retail cd so I can't be certain what the issue is. Did you select all the samples and other optional features? They may be on the second CD so you would only have to mount the second CD if you needed to install something from it. There may be other optional files that only need to be installed if your system needs them. Many options default to run from CD or install on first use so if you didn't change those to run from my computer, you may be prompted as you use the feature to mount the other CD. ...

How do I move .pst file?
My .pst file is very large, and I want to move it to another drive. It is at C:\Documents and Settings\My Name\Local Settings\Application Data\Microsoft\Outlook\outlook.pst [not wrapped of course]. I could move it "manually" but I don't want to confuse Outlook, and I can't find any way to tell Outlook the new location. Microsoft Outlook 2000 SR-1 Internet-only profile. Windows 2000 Version 5.0 build 2195 Service Pack 4. Thanks! On Sat, 20 Dec 2003 13:32:42 -0800, "Robert Cheshire" <abuse@spamme.not> wrote: >My .pst file is very large, and I want ...

Open Multiple files from Open dialog
Hi, How can i select multiple .xls to open & also capture the name of each of those .xls when i invoke the Open dialog from the code ? Currently, i am using the following: 1. File_Open = Application.GetOpenFileName() 2. Workbooks.Open Filename:=File_Open Point 1 enables me to select only ONE file i.e allows to select the filename thru the Open dialog. Point 2 actually opens the file. So, i want to know how i can make the Open dialog allow me to select multiple files & how do i capture the names of the files selected. Any help in this regard is appreciated. Thank You in...

WAB DLL file
For some reason I can't get to my address book in outlook. comes up it can't find the WAB DLL file. ???????????????????????????????????????????????????? What version of Outlook installed on what o/s Outlook hasnt used a wab.dll since outlook 2k(?) "Tony Miller" <tonyyamahamiller@comcast.net> wrote in message news:%2346VH1%23qJHA.4260@TK2MSFTNGP06.phx.gbl... > For some reason I can't get to my address book in outlook. > comes up it can't find the WAB DLL file. > ???????????????????????????????????????????????????? let me guess -- outlook 2000 on v...

How do I save Publisher files to single html files?
When I used Publisher 95 years ago I could save a Publisher file directly to a single HTML file which I could attach to an email. I have been unable to do this with Publisher 2000. If I try to convert the Design to a web-page I get a complicated list of files that totally wipes out my formatting. Lawrence B wrote: > When I used Publisher 95 years ago I could save a > Publisher file directly to a single HTML file which I > could attach to an email. I have been unable to do this > with Publisher 2000. If I try to convert the Design to a > web-page I get a complicated list of f...

Open email .PST files to Outlook Express (Win 9x only) Free without Outlook
DISCLAIMER: Microsoft doesn't recommend this strategy. Neither do I. IT MAY BREAK STUFF. It may stop any MAPI enabled programs from working if installed. It may cause problems that are just plain weird. Although, Corel WP8 insists on installing this anyway, so... Make backups of your .pst. Use the backup to test. Do NOT use original ..pst files, as this method will shrink them. This method can be used to retrieve all email and attachments (beware that OE may block attachments!) and possibly Outlook Notes (not sure.) It doesn't merge/import the contact list of Outlook. Look, in my c...

File read
I've found this script http://www.codeassassin.com/blog/PermaLink,guid,e05d6a2c-fdc2-4a96-9d72-d038f9306945.aspx which computes the MD5 file of file, this works really great, but since I'm going to deal with some really big file (over 1 GB) is going to take a long time. So my goal is to add 1 or 2 steps to minimize the number of hash to compute. So instead of hashing the entire file, I would like to hash the first 64KB and also the last 64KB of the file, hashing only 128KB should be extremely fast, so if a file has the same size, the same first 64KB hash,and the last 64KB has...

Attached file size (very) different on Outlook and OWA
I noticed that an attached zip file on an e-mail was - correctly - shown as 27 MB in Outlook, but in OWA it's size was said to be 36 MB. That's quite a difference I think. Can anyone explain it? Regards, Kim When you convert MAPI to MIME, it bloats about 30%. "Kim Stahnke" <kimstahnke@tdcadsl.dk> wrote in message news:uqPveopIGHA.1288@TK2MSFTNGP09.phx.gbl... >I noticed that an attached zip file on an e-mail was - correctly - shown as >27 MB in Outlook, but in OWA it's size was said to be 36 MB. > That's quite a difference I think. Can anyone ex...

File attachment #2
When a file is sent as an attachment in Outlook Express, it appears in the "Attach" field right below the "Subject" field when the message is viewed in the "Sent Items" folder by the sender or in the "In Box" by the recipient. . In Outlook, when composing a message, a file is attached, the file shows in the "Attach" field (as in Outlook Express). But when the message is viewed in the "Sent Items" folder by the sender or viewed by the recipient in the "In Box", the attached file shows at the bottom of the message!? Is ther...

i cannot register the key while i registered it before and it wor.
i registered it before with the same product key and now its not working i really need help.. I'd suggest calling microsoft -- Regards, Peo Sjoblom "annie" <annie@discussions.microsoft.com> wrote in message news:2E69A2C2-93FB-4BA3-9ED8-90A9E0C5C1E1@microsoft.com... > i registered it before with the same product key and now its not working i > really need help.. ...

How do I back up my complete "my document" file?
I do not know how to back up my "my documents" file and would appreciate knowing how. Do you have any sort of large writeable media (writeable CDs, DVDs, etc)? If so you could try copying your My Documents folder on to them "Dougal" <Dougal@discussions.microsoft.com> wrote in message news:8DD55FCB-B576-408F-9BFC-B736ABE17CE6@microsoft.com... >I do not know how to back up my "my documents" file and would appreciate > knowing how. The next issue of "Computeractive" will cover this in some depth. "Dougal" <Dougal@discussi...

Cannot attach zip files to messages
For some reason, when I open a message window in Outlook 2002, I cannot attach a zip file (or any attachment that has a file extention that starts with the letter z). If I rename the file extention, I can attach the file. I can also send the same attachment if I right click on it and create a new message by selecting the "send to" option. Thoughts? I can't think of anything in Outlook that would do this. Any error messages? Andrew wrote: > For some reason, when I open a message window in Outlook > 2002, I cannot attach a zip file (or any attachment that > has ...

Limitation on inf and cat file name length?
Hi Driver Experts: I have a simple question: Must the inf and cat file names be in 8.3 format? Can they be longer than 8 chars? Any difference on 64-bit OS? Thanks in advance. Polaris there are no file name length restrictions in general. 64 bit XP (which is really server 2003 64 bit under the covers) has some restrictions on cat file name length, I think around 28 chars d -- This posting is provided "AS IS" with no warranties, and confers no rights. "Polaris" <etpolaris@hotmail.com> wrote in message news:uo#FMe5fKHA.6096@...

Retrieving exe file from email
Is there a way to get to the "exe" attachment blocked automatically by the Outlook? I have send an "exe" file from my friend's computer to my email, and forgot to rename the extension before mailing it. Now, the Outlook on my computer has blocked the access to this file, and I have no possibility to retrive it and save. I cannot even resent it somewhere else with the attachment, nothing. The attachmement is simply not accessible. Outlook has swallwed it, and does not allow any accesss to it. This seems to me like a very stupid solution to the security -- Microsof...

Old Wk3 Files
For Excel 2010, is there any way to get it to read old Lotus files? On Wed, 19 Jan 2011 17:28:40 -0800 (PST), Frank <FRBChemE@aol.com> wrote: >For Excel 2010, is there any way to get it to read old Lotus files? Run the old lotus app in a DOSBox DVM, and export the file in ASCII delimited format. If it already in ASCII form, you can import it directly. I am pretty sure there are some free apps in Linux that will open them as well. You would burn a Linux Live distro disk (Ubuntu Live DVD), boot that, and then run the compatible app within that session, open the old file, an...

EDB file to PST file?
Is there a utility (FREE) that I can convert an edb file to PST? I have some EDB files I want to take out some mail out of but not restore the whol thing. I test some COSTLY utilies but on need this for one time only. Thanks Mike What version of Exchange? Perhaps you could build a recovery server and do a disaster recovery scenario? -- Martin Blackstone MVP - Exchange http://www.swinc.com/resource/exchange.htm http://www.swinc.com/resource/e2kfaq_appxc.htm "Mike" <massey@rmci.net> wrote in message news:psst001mj15vod5fphqpfjc7hk39975d5l@4ax.com... > Is there a utilit...

import file so that it is a actual csv file, no excel cell version
How can I import a spreadsheet file from finance.yahoo.com for the history prices of a stock and import it into my charting software. My charting software reads ASCII "DOHLCV" or D,O,H,L,C,V or "Date", "O", "H", "L", "C", "V" . I have tried for a week trying to manipulate the data to be read by my charting software but it will not take it. When downloading data it automatically opens excel 97 spreadsheet and inserts the data. I save it as a CSV file but my charting program will not read it and when I open the fil...

Cannot open or save a tif file
Since 2 days i cannot open of save a tif file attached to a email. Can some one help? I am using outlook 2003 and windows xp Thanks Hans Do you have any more informaton or an error message? Can you save other types of files? Can you save a tif file from a different email? "hans" <hans_jeucken@hotmail.com> wrote in message news:258E9706-81FD-4FCB-8A50-2E8F68D26EFA@microsoft.com... > Since 2 days i cannot open of save a tif file attached to a email. > Can some one help? > I am using outlook 2003 and windows xp > > Thanks Hans The error message says that i d...

register questions
I have been using Money 2002 for some time and have had previous money versions. During the last 2 week time period my register quite going back to the beginning. Now all I get is the last 3 years worth of transactions. I have set the view to show all dates. The payees and transactions are still in the database, just need the register to REALLY show ALL dates. Comments? In microsoft.public.money, ballworth@comcast.net wrote: >I have been using Money 2002 for some time and have had >previous money versions. During the last 2 week time >period my register quite going back to t...

OutputDebugString to a file???
Hello all Is it possible to redirect all the output of OutputDebugString to a flat file? I am thinking of creating a listener that captures the output (from OutputDebugString fn.) from my app and writes them to a flat file. But I am not sure how to go about creating a listener. Googled results in some .NET listeners, however my requirement is for VC++ app. any pointers would be much appreciated -Jam "Jam" <jamni18@gmail.com> wrote in message news:1154074768.449365.205840@s13g2000cwa.googlegroups.com... > > Is it possible to redirect all the output of OutputDebugStrin...

Great Plains 9 Restore
Hi, I am trying to upgrade from great plains 9 to great plains 9 sp2. So, we have setup up a test server where I have installed GP 9 and restored the data. At the moment I am just reading the KB923671 from customer source and one of the prequisites that you need to do before installing the service pack deals with Reports.dic and Forms.dic My question is when you install GP on such a scanario does one have to copy/restore the Reports.dic and Forms.dic files from the live system [or from the backups]. Or are they irrelevant? Thanks Sanjay, The FORMS.DIC and REPORTS.DIC are irreleva...

Excel 2003 file freezes laptop
I took a laptop away from the office and tried to open a large spreadsheet on the local C: drive. Each time I tried the laptop froze and had to be rebooted. When I connected back to the LAN at work, and opened the same file on the local C: drive I had no problems. What could cause this? If there is any corruption is there a way to decompile or something as you would in Access? Thanks, Mich ...

Money Updates: "Money encountered an error processing the download file ('SMRTINET.ini').
My M04 has not been doing Money Updates (other parts of update are doing so: quotes, accounts) for a month now. The Call Summary for Money Updates says Money encountered an error processing the download file ('SMTINET.INI'). Out of curiosity I looked for such a file name on the computer--none. We have two accounts on Money. The other account is NOT encountering any such problem--Money Updates are working fine for it. No changes for either account of any seeming relevance preceded the loss of updates on the one account. Questions: (1) Does anyone know how to fix this? (2) Thes...