Get Default shell command
-
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
-
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
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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
-
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.
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 :-(
-
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 :-(
-
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
hey buddy thanks a lot, yes that function sound promising, will give a try and will post results here. regards