how to associate files with application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ashok

    #1

    how to associate files with application

    hi,
    i want to know how to make a specific type of file open in an
    application i developed in python when the user clicks on the file.(in
    windows) for eg. a .txt file when clicked opens in notepad, a .doc file
    when clicked opens in MS-word. In the same way i want to make a .xyz
    file open in the application i developed when clicked.
    thanks in advance for any advice.

  • jmdeschamps@gmail.com

    #2
    Re: how to associate files with application


    Ashok wrote:[color=blue]
    > hi,
    > i want to know how to make a specific type of file open in an
    > application i developed in python when the user clicks on the file.(in
    > windows) for eg. a .txt file when clicked opens in notepad, a .doc file
    > when clicked opens in MS-word. In the same way i want to make a .xyz
    > file open in the application i developed when clicked.
    > thanks in advance for any advice.[/color]

    Not an expert in this (OS-related) field but in Windows I think that
    would be a Registry thing...

    Maybe this article could help you start somewhere...


    Good Luck, and maybe you can reply-post your eventual success recipe!

    Comment

    • Lasse Vågsæther Karlsen

      #3
      Re: how to associate files with application

      Ashok wrote:[color=blue]
      > hi,
      > i want to know how to make a specific type of file open in an
      > application i developed in python when the user clicks on the file.(in
      > windows) for eg. a .txt file when clicked opens in notepad, a .doc file
      > when clicked opens in MS-word. In the same way i want to make a .xyz
      > file open in the application i developed when clicked.
      > thanks in advance for any advice.
      >[/color]

      You need to add several registry keys to do this, here's a short version
      of what you need to do:

      Example assumes you want to:

      1. associate .ext with C:\Program Files\MyProgram \prog.exe
      2. pass on any extra arguments to prog.exe (ie. test.ext 1 2 3 would
      send 1 2 3 as well to prog.exe)
      3. associate the icon of prog.exe to any file with a .ext extension

      Ok, here's what you need to do:

      1. Under HKEY_CLASSES_RO OT, add a key (folder) with the name .ext
      2. Open that key, and set the (Default) value to MyProgramExtend edFile
      (this name is something you choose yourself and should be a "identifier "
      that identifies the file type. If your program supports several types of
      files, make up unique identifiers for each.)
      3. Under HKEY_CLASSES_RO OT, add another key, this time with the same
      name you made up in 2. above, ie MyProgramExtend edFile
      4. Open that key, and set the (Default) value to a textual description
      of the type of file. This is what will show up in explorer in the file
      type column. If you leave this empty, the description will be .EXT File
      5. Inside MyProgramExtend edFile, add another key with the name shell
      (lower-case is typical, can probably be Shell or whatever)
      6. Inside shell, create another key with the name open
      7. Inside open, create another key with the name command
      8. Inside command, Set the (Default) value to:
      "C:\Program Files\MyProgram \prog.exe" "%1" %*

      Note that you need the quotes as specified above, exactly like written

      9. Go back to MyProgramExtend edFile and create another key with the name
      DefaultIcon
      10. Inside DefaultIcon, set (Default) value to:
      "C:\Program Files\MyProgram \prog.exe", 0

      This will pick the first icon in prog.exe resource to show for the
      files. Use 1 for second, etc.

      There are also other commands you can add. If you want to be able to
      right-click on the file and select a menu item to process the file in a
      specific way, for instance by passing along specific parameters to
      prog.exe, you can add more keys than "open" on the level open is
      created. The (Default) value inside the key is then the text of the menu
      item.

      To find examples, just find a file extension in Windows that behaves the
      way you want your own to behave and look through HKEY_CLASSES_RO OT\.ext
      to find the details you want.

      --
      Lasse Vågsæther Karlsen

      mailto:lasse@vk arlsen.no
      PGP KeyID: 0x2A42A1C2

      Comment

      • Colin J. Williams

        #4
        Re: how to associate files with application

        Lasse Vågsæther Karlsen wrote:[color=blue]
        > Ashok wrote:
        >[color=green]
        >> hi,
        >> i want to know how to make a specific type of file open in an
        >> application i developed in python when the user clicks on the file.(in
        >> windows) for eg. a .txt file when clicked opens in notepad, a .doc file
        >> when clicked opens in MS-word. In the same way i want to make a .xyz
        >> file open in the application i developed when clicked.
        >> thanks in advance for any advice.
        >>[/color]
        >
        > You need to add several registry keys to do this, here's a short version
        > of what you need to do:
        >
        > Example assumes you want to:
        >
        > 1. associate .ext with C:\Program Files\MyProgram \prog.exe
        > 2. pass on any extra arguments to prog.exe (ie. test.ext 1 2 3 would
        > send 1 2 3 as well to prog.exe)
        > 3. associate the icon of prog.exe to any file with a .ext extension
        >
        > Ok, here's what you need to do:
        >
        > 1. Under HKEY_CLASSES_RO OT, add a key (folder) with the name .ext
        > 2. Open that key, and set the (Default) value to MyProgramExtend edFile
        > (this name is something you choose yourself and should be a "identifier "
        > that identifies the file type. If your program supports several types of
        > files, make up unique identifiers for each.)
        > 3. Under HKEY_CLASSES_RO OT, add another key, this time with the same
        > name you made up in 2. above, ie MyProgramExtend edFile
        > 4. Open that key, and set the (Default) value to a textual description
        > of the type of file. This is what will show up in explorer in the file
        > type column. If you leave this empty, the description will be .EXT File
        > 5. Inside MyProgramExtend edFile, add another key with the name shell
        > (lower-case is typical, can probably be Shell or whatever)
        > 6. Inside shell, create another key with the name open
        > 7. Inside open, create another key with the name command
        > 8. Inside command, Set the (Default) value to:
        > "C:\Program Files\MyProgram \prog.exe" "%1" %*
        >
        > Note that you need the quotes as specified above, exactly like written
        >
        > 9. Go back to MyProgramExtend edFile and create another key with the name
        > DefaultIcon
        > 10. Inside DefaultIcon, set (Default) value to:
        > "C:\Program Files\MyProgram \prog.exe", 0
        >
        > This will pick the first icon in prog.exe resource to show for the
        > files. Use 1 for second, etc.
        >
        > There are also other commands you can add. If you want to be able to
        > right-click on the file and select a menu item to process the file in a
        > specific way, for instance by passing along specific parameters to
        > prog.exe, you can add more keys than "open" on the level open is
        > created. The (Default) value inside the key is then the text of the menu
        > item.
        >
        > To find examples, just find a file extension in Windows that behaves the
        > way you want your own to behave and look through HKEY_CLASSES_RO OT\.ext
        > to find the details you want.
        >[/color]
        I'm no Windows expert but I think that, using Windows Explorer, one can,
        with a right mouse click, select "Open With".

        You can then choose the appropriate executable. I believe that, if you
        had set the "Always open with this program" box, then the registry is
        automatically updated.

        Colin W.

        Comment

        • Dennis Lee Bieber

          #5
          Re: how to associate files with application

          On Fri, 28 Oct 2005 09:48:27 -0400, "Colin J. Williams"
          <cjw@sympatico. ca> declaimed the following in comp.lang.pytho n:

          [color=blue]
          > I'm no Windows expert but I think that, using Windows Explorer, one can,
          > with a right mouse click, select "Open With".
          >
          > You can then choose the appropriate executable. I believe that, if you
          > had set the "Always open with this program" box, then the registry is
          > automatically updated.
          >[/color]
          You could also use the "file types" page (on XP it is under
          "tools/folder options", W9x puts it under "view/folder options" I
          believe). to define new file types, and then define all the actions
          available for it. The default would be the Open action, but you might
          add a print or edit action; these would show up using a right-click on
          the file.
          --[color=blue]
          > =============== =============== =============== =============== == <
          > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
          > wulfraed@dm.net | Bestiaria Support Staff <
          > =============== =============== =============== =============== == <
          > Home Page: <http://www.dm.net/~wulfraed/> <
          > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

          Comment

          • Lasse Vågsæther Karlsen

            #6
            Re: how to associate files with application

            Dennis Lee Bieber wrote:[color=blue]
            > On Fri, 28 Oct 2005 09:48:27 -0400, "Colin J. Williams"
            > <cjw@sympatico. ca> declaimed the following in comp.lang.pytho n:
            >
            >
            >[color=green]
            >>I'm no Windows expert but I think that, using Windows Explorer, one can,
            >>with a right mouse click, select "Open With".[/color][/color]
            <snip>

            There are several ways to do this using Windows Explorer. I was under
            the assumption the OP wanted to know how he could automate it since that
            is what you typically want to do with applications you write.

            --
            Lasse Vågsæther Karlsen

            mailto:lasse@vk arlsen.no
            PGP KeyID: 0x2A42A1C2

            Comment

            • Ashok

              #7
              Re: how to associate files with application

              Thanks Lasse, that was really helpful

              Comment

              Working...