Chip's Tips for Developers

Contains coding, but not narcotic.

Launching Windows applications by associated file extension for ruby (or C#)

January 24th, 2007 1:14:10 pm pst by 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!

8 Responses to “Launching Windows applications by associated file extension for ruby (or C#)”

  1. Ken Leland says:

    Worked like a charm for opening the default browser in windows xp. Thanks!

  2. Pedro says:

    Blame google for that :)
    Search by “c# launch associated application” and see what I mean.

    And thanks, BTW.

  3. Ahmad Khader says:

    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#

  4. Stefan says:

    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}”

Leave a Reply

Better Tag Cloud