Launching Windows applications by associated file extension for ruby (or C#)
Sterling Camden
Quite frequently, sometimes several times a day, a Google search for something like “launch application by file extension” or “shellexecute” will bring the errant searcher to this post, which describes how to do just exactly that — in Synergy/DE. Unfortunately, most of these seekers of wisdom usually add “C#” or “ruby” to their queries.
I hate to see people land on my site and not get the answer they’re looking for. So lets give them something to find, shall we?
No need to create a C# example because there’s a great one over on The Code Project.
However, a good Ruby example eluded my search, so I whipped one up. You can download it below. As you might expect, it creates a Win32API object for the necessary linkage to ShellExecute in shell32.dll, then calls it to launch the associated application for whatever file and verb you pass. Naturally, this only works on Microsoft Windows platforms.
Posted in C#, Ruby, Wildly popular, Windows |
8 Comments » RSS 2.0 | Sphere it!





Worked like a charm for opening the default browser in windows xp. Thanks!
Glad to be of help, Ken!
Blame google for that
Search by “c# launch associated application” and see what I mean.
And thanks, BTW.
You’re welcome, and I don’t mind the traffic.
i want to ask how can i let Windows open my extension for example if i have extension (“*.mp”) how can i let windows to open it using C#
Does this help? http://www.beansoftware.com/Windows-Forms-Tutorials/Deploy-NET-Windows-Application.aspx
Look under “Add/Remove File Types”
Just for completeness:
Here are two ways to open a file with the associated application with ruby under linux.
under KDE use:
system “kfmclient exec #{file}”
under gnome:
system “gnome-open #{file}”
Thanks for the tip, Stefan!