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 / C++ / MFC
  4. Get Default shell command

Get Default shell command

Scheduled Pinned Locked Moved C / C++ / MFC
tutoriallinuxhelp
11 Posts 4 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.
  • V Offline
    V Offline
    vikrant kpr
    wrote on last edited by
    #1

    Hey Friends Any idea how to get default command for any given file type e.g for .cpl shell command is open with control panel or for .txt shell command is Open Any sample / example can be of real help Regards

    S _ 2 Replies Last reply
    0
    • V vikrant kpr

      Hey Friends Any idea how to get default command for any given file type e.g for .cpl shell command is open with control panel or for .txt shell command is Open Any sample / example can be of real help Regards

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      You mean what ShellExecute[^] does, except without actually performing the command? I don't know of anything that does that, probably because the only thing you really want to do with a command like that is execute it.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • V vikrant kpr

        Hey Friends Any idea how to get default command for any given file type e.g for .cpl shell command is open with control panel or for .txt shell command is Open Any sample / example can be of real help Regards

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        As Stuart said, you probably just want to execute the file using ShellExecute. The command for the default operation is stored in the registry. You should be able to read it for most of the file types. There is no guarantee that all file types have this information. Here goes - Open the HKEY_CLASSES_ROOT registry key. This hive will have a subkey with the extension of a file like .txt or .cpl The default value of this key will contain another value like txtfile for .txt files and cplfile for .cpl files. The HKEY_CLASSES_ROOT key also has subkeys with these values like txtfiles and cplfiles. These subkeys in-turn will have a subkey called shell. The subkeys of shell contain the names of the supported commands like Open, Runas etc. Each of these keys contain a subkey called command whose default value is the actual command that is executed.

        «_Superman_» I love work. It gives me something to do between weekends.

        V 1 Reply Last reply
        0
        • _ _Superman_

          As Stuart said, you probably just want to execute the file using ShellExecute. The command for the default operation is stored in the registry. You should be able to read it for most of the file types. There is no guarantee that all file types have this information. Here goes - Open the HKEY_CLASSES_ROOT registry key. This hive will have a subkey with the extension of a file like .txt or .cpl The default value of this key will contain another value like txtfile for .txt files and cplfile for .cpl files. The HKEY_CLASSES_ROOT key also has subkeys with these values like txtfiles and cplfiles. These subkeys in-turn will have a subkey called shell. The subkeys of shell contain the names of the supported commands like Open, Runas etc. Each of these keys contain a subkey called command whose default value is the actual command that is executed.

          «_Superman_» I love work. It gives me something to do between weekends.

          V Offline
          V Offline
          vikrant kpr
          wrote on last edited by
          #4

          yeah thanks will give it a try so whatever extension (xxx) i will append like xxxfile and then will follow the above procedure in case i do not find the shell command, i will use open shellexecute is used at lots of places, however with metacafe, i got warning saying your program is going to change something into shell

          _ 1 Reply Last reply
          0
          • V vikrant kpr

            yeah thanks will give it a try so whatever extension (xxx) i will append like xxxfile and then will follow the above procedure in case i do not find the shell command, i will use open shellexecute is used at lots of places, however with metacafe, i got warning saying your program is going to change something into shell

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            vikrant kpr wrote:

            so whatever extension (xxx) i will append like xxxfile

            Wrong. Please read my earlier post carefully. The default value of the extension (.xxx) will contain the name to search. It may not always be xxxfile. It could be xxxyyy

            «_Superman_» I love work. It gives me something to do between weekends.

            V 1 Reply Last reply
            0
            • _ _Superman_

              vikrant kpr wrote:

              so whatever extension (xxx) i will append like xxxfile

              Wrong. Please read my earlier post carefully. The default value of the extension (.xxx) will contain the name to search. It may not always be xxxfile. It could be xxxyyy

              «_Superman_» I love work. It gives me something to do between weekends.

              V Offline
              V Offline
              vikrant kpr
              wrote on last edited by
              #6

              hey buddy that's really great now i get it and thanks for the correction HKEY_CLASSES_ROOT\.cpl ' default value reads cplfile and then to read HKEY_CLASSES_ROOT\cplfile\shell\cplopen ' default value can be passed to shellexecute now the trick seems to find the name cplopen as the shell key can have many subkeys rest all seems good

              _ 1 Reply Last reply
              0
              • V vikrant kpr

                hey buddy that's really great now i get it and thanks for the correction HKEY_CLASSES_ROOT\.cpl ' default value reads cplfile and then to read HKEY_CLASSES_ROOT\cplfile\shell\cplopen ' default value can be passed to shellexecute now the trick seems to find the name cplopen as the shell key can have many subkeys rest all seems good

                _ Offline
                _ Offline
                _Superman_
                wrote on last edited by
                #7

                To use ShellExecute on .cpl you simple do this ShellExecute(NULL, _T("open"), _T("cplfile.cpl"), NULL, NULL, SW_SHOW); The API will take care of finding out the command for it. You do not need to do this yourself.

                «_Superman_» I love work. It gives me something to do between weekends.

                V 2 Replies Last reply
                0
                • _ _Superman_

                  To use ShellExecute on .cpl you simple do this ShellExecute(NULL, _T("open"), _T("cplfile.cpl"), NULL, NULL, SW_SHOW); The API will take care of finding out the command for it. You do not need to do this yourself.

                  «_Superman_» I love work. It gives me something to do between weekends.

                  V Offline
                  V Offline
                  vikrant kpr
                  wrote on last edited by
                  #8

                  that's the issue cplfile does not have shell command named Open it has Open with Control Panel shell command now even with above both items, it is not invoking the control panel item //ShellExecute(NULL, _T("Open with Control Panel"), _T("c:\\windows\\system32\\main.cpl"), NULL, NULL, SW_SHOW); ShellExecute(NULL, _T("Open"), _T("c:\\windows\\system32\\main.cpl"), NULL, NULL, SW_SHOW); it seems it would require control.exe to be passed in with open and pass the cpl file as parameter

                  1 Reply Last reply
                  0
                  • _ _Superman_

                    To use ShellExecute on .cpl you simple do this ShellExecute(NULL, _T("open"), _T("cplfile.cpl"), NULL, NULL, SW_SHOW); The API will take care of finding out the command for it. You do not need to do this yourself.

                    «_Superman_» I love work. It gives me something to do between weekends.

                    V Offline
                    V Offline
                    vikrant kpr
                    wrote on last edited by
                    #9

                    it works as given below ShellExecute(NULL, _T("Open"), _T("control.exe"), _T("main.cpl"), NULL, SW_SHOW); however that does not make it generic :-(

                    R 1 Reply Last reply
                    0
                    • V vikrant kpr

                      it works as given below ShellExecute(NULL, _T("Open"), _T("control.exe"), _T("main.cpl"), NULL, SW_SHOW); however that does not make it generic :-(

                      R Offline
                      R Offline
                      Rozis
                      wrote on last edited by
                      #10

                      I don't know if this will help you but using FindExecutable() you can get the program that is associated with a file without looking in the registry Rozis

                      V 1 Reply Last reply
                      0
                      • R Rozis

                        I don't know if this will help you but using FindExecutable() you can get the program that is associated with a file without looking in the registry Rozis

                        V Offline
                        V Offline
                        vikrant kpr
                        wrote on last edited by
                        #11

                        hey buddy thanks a lot, yes that function sound promising, will give a try and will post results here. regards

                        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