Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Default program of file.

Default program of file.

Scheduled Pinned Locked Moved C#
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahul RK
    wrote on last edited by
    #1

    Hello friends, can we get default program of file specified. E.g. default program for .mp3 file may be windows media player/winamp like that. Is there any method which gives such details of default program. thanks in advance. Rahul Kulkarni

    C K H 3 Replies Last reply
    0
    • R Rahul RK

      Hello friends, can we get default program of file specified. E.g. default program for .mp3 file may be windows media player/winamp like that. Is there any method which gives such details of default program. thanks in advance. Rahul Kulkarni

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You get that info via the registry, I don't know of a method that will look it up for you, however.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      V T 2 Replies Last reply
      0
      • C Christian Graus

        You get that info via the registry, I don't know of a method that will look it up for you, however.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        T Offline
        T Offline
        Tormod Fjeldskaar
        wrote on last edited by
        #3

        To see how this information is stored in the registry, you may want to read what Microsoft has to say about file types[^].

        1 Reply Last reply
        0
        • C Christian Graus

          You get that info via the registry, I don't know of a method that will look it up for you, however.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          This page (http://msdn2.microsoft.com/en-us/library/aa969375.aspx[^]) describes the keys used.

          Vasudevan Deepak Kumar Personal Homepage Tech Gossips

          T 1 Reply Last reply
          0
          • V Vasudevan Deepak Kumar

            This page (http://msdn2.microsoft.com/en-us/library/aa969375.aspx[^]) describes the keys used.

            Vasudevan Deepak Kumar Personal Homepage Tech Gossips

            T Offline
            T Offline
            Tormod Fjeldskaar
            wrote on last edited by
            #5

            I can't see that it does. The page you point to describes how the Default Programs API works, i.e. how to tell windows the capabilities of a certain application.

            1 Reply Last reply
            0
            • R Rahul RK

              Hello friends, can we get default program of file specified. E.g. default program for .mp3 file may be windows media player/winamp like that. Is there any method which gives such details of default program. thanks in advance. Rahul Kulkarni

              K Offline
              K Offline
              Kumar Arun
              wrote on last edited by
              #6

              MyComputer\HKey_Classes_Root\AudioCD\Shell\Play\Command Check it

              Arun Kr

              1 Reply Last reply
              0
              • R Rahul RK

                Hello friends, can we get default program of file specified. E.g. default program for .mp3 file may be windows media player/winamp like that. Is there any method which gives such details of default program. thanks in advance. Rahul Kulkarni

                H Offline
                H Offline
                Hessam Jalali
                wrote on last edited by
                #7

                as I know it can be retrieved with shell32 FindExecutable API but sometimes the results is not like what is Expected Maybe this going to help

                    class Shell32Utils
                    {
                        const int FILENOASSOCIATED = 31;
                        const int FILENOTFOUND = 2;
                        const int PATHNOTFOUND = 3;
                        const int SUCCESS = 32; //and longer
                        const int BADFORMAT = 11;
                
                        
                
                        [DllImport("shell32", EntryPoint = "FindExecutable")]
                        static extern int FindExecutable(string file, string directory, [MarshalAs(UnmanagedType.LPStr)] StringBuilder result);
                
                
                        public static string Find(string file)
                        {
                            string fileName=System.IO.Path.GetFileName(file);
                            string filePath = System.IO.Path.GetDirectoryName(file)+"\\";
                
                            System.Text.StringBuilder res = new StringBuilder(1024);
                
                            int stat = FindExecutable(fileName, filePath,  res);
                
                            switch (stat)
                            {
                                case FILENOASSOCIATED: throw new Exception("File Not Associated");
                                case FILENOTFOUND: throw new Exception("FileNot Found");
                
                                case PATHNOTFOUND: throw new Exception("Path not Found");
                
                                case BADFORMAT: throw new Exception("Bad Format");
                
                                default: if (stat >= SUCCESS) return res.ToString();
                                    else throw new Exception("Unknown Error");
                            }
                        }       
                    }
                

                good luck

                R 1 Reply Last reply
                0
                • H Hessam Jalali

                  as I know it can be retrieved with shell32 FindExecutable API but sometimes the results is not like what is Expected Maybe this going to help

                      class Shell32Utils
                      {
                          const int FILENOASSOCIATED = 31;
                          const int FILENOTFOUND = 2;
                          const int PATHNOTFOUND = 3;
                          const int SUCCESS = 32; //and longer
                          const int BADFORMAT = 11;
                  
                          
                  
                          [DllImport("shell32", EntryPoint = "FindExecutable")]
                          static extern int FindExecutable(string file, string directory, [MarshalAs(UnmanagedType.LPStr)] StringBuilder result);
                  
                  
                          public static string Find(string file)
                          {
                              string fileName=System.IO.Path.GetFileName(file);
                              string filePath = System.IO.Path.GetDirectoryName(file)+"\\";
                  
                              System.Text.StringBuilder res = new StringBuilder(1024);
                  
                              int stat = FindExecutable(fileName, filePath,  res);
                  
                              switch (stat)
                              {
                                  case FILENOASSOCIATED: throw new Exception("File Not Associated");
                                  case FILENOTFOUND: throw new Exception("FileNot Found");
                  
                                  case PATHNOTFOUND: throw new Exception("Path not Found");
                  
                                  case BADFORMAT: throw new Exception("Bad Format");
                  
                                  default: if (stat >= SUCCESS) return res.ToString();
                                      else throw new Exception("Unknown Error");
                              }
                          }       
                      }
                  

                  good luck

                  R Offline
                  R Offline
                  Rahul RK
                  wrote on last edited by
                  #8

                  Thank you very much. It works fine :) Rahul Kulkarni

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups