launch my app on double click of certain file extensions

Kurt

Regular
Joined
Feb 14, 2003
Messages
99
Location
Copenhagen
Hi,

Like with for example MSWord, whenever a .doc file is dubbelclicked in Windows, Windows starts MSWord and probably the full path to the file is passed as an argument to MSWord as MSWord loads the file properly.

I would like to create the same kind of functionality for my program. So I 'm basically looking for some way to connect my personal file extension(s) to my program when installed on a Windows (2000 - XP) machine, and for some way to let my app pick up the path to the file that caused the program to launch.

Hope someone knows where to start or look at...
 
Hummm... I don't know if a Deploy Solution do the trick but here is programmed one.

If you go in the registry (yes ! everything start there!) under HKEY_CLASSES_ROOT
you'll find the .txt Key. Set your selection on it. You'll see under (Default) "txtfile". Here is what we need. Now (still under CLASSES_ROOT) search txtfile key.

You got it ? Good ! Now open it and seak "shell" open it and seek "open" and now seek "command". That's the (Default) of the "command" key that we want. you that ?

%SystemRoot%\system32\NOTEPAD.EXE %1

Do you got it ?

The file is used as a parameter. So you'll have to manage parameter in your app (that's the first thing. And next... you'll have to create your own personal key.

You'll have to match your extension however ! (just like .txt)
And set a default that correspond to the correct key that will keep needed information.

Have fun my friend ! If you want more detail ... ask me ! I'll try to find some article on that... I don't know if it exists... if not... I have something to work on !!!!!!
 
Yes I would like some more explanation if you 're up to it. Like for example how to make the registery entries needed during installation or first run of the app... Cause I guess I 'll have to make some similar structure in the registry like the NotePad one. thanx in advance
 
Here is some notion on the Registry.

You'll need the following assembly :
Microsoft.Win32.Registry

For the registry... here is some "sample" code :

Does the Key exists ?
Visual Basic:
Dim MyKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(".txt", False) 
If Not (MyKey Is Nothing) Then 
MessageBox.Show("The Key is there") 
Else 
MessageBox.Show("The Key is not there") 
End If
Thanks to Denaes for this post (I modified it a little bit)

And for writing data... well take a look at this thread
 
while deploying ur project
VS.NET gives u the option to associate files types with ur App.
through the File Types Editor
 
Ya. It's the best solution to associate your file at install time. However... if you want to make sure that your file is still associated with your app... it's the only way to go.

Depend of what you need.
 
Thanx. How to capture the parameter in the code (the path to the file double-clicked)? And what did you mean with creating my own personal key Arch4ngel?
 
I set the association from the file type editor now, using Visual Studio. How to make a certain piece of code run to process the dubble clicked file now?
 
Well... maybe you could send a certain parameter. Next... in your app... you could analyze to verify the presence of the parameter. the parameter should be in System.Environnement.CommandLine (I don't know if it's EXACTLY this)

play a little bit with this... and if the command line isn't empty ..... well.... you could do anything you want.
 
Yes, when I add a file type in the File Types Editor, I have to specify the .exe that will run (command property). For that file type, I then have to specify an action that allows a parameter. The default value of that parameter is '%1', which seems to be the path of the file dubble clicked - exactly what I want! I managed to check in the Main routine of the .exe if there's a filepath and if so, I call a specilased constructor of my main form, taking the filepath as a parameter. I did this by defining my Main methode as taking an array of strings. That way I can just check if args (=the array of strings) has a Length of 0 or not. If not, args[0] contains the path of the file. And it works.... The commandline property would also work, but it would involve some regular expressions to extract the relevant data.

But what I still don't understand is the Verb property of the attached action. The microsoft documentation says:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vbtskaddingdeletingverbs.asp said:
select the Verb property and type a verb. This is the name that you will use programmatically within your application to run code when the action is invoked.

But I can't see how this would work, I mean how to pick up from my code the name of the verb associated with the action? Let's say I just want an action called 'verify' that when clicked shows a messagebox saying wether or not the file contains valid data. I searched the web for this problem quite a bit, but I can't seem to find how to use the Verb property in the Deploy project from my source code.
 
ok, this looks promising

Code:
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
switch (p.StartInfo.Verb){...}
 
Back
Top