Shell open & working dir
-
I inserted in the registry (HKCR/myappdata/shell/open) the command line to open a file ("c:/programs dir/my app dir/myapp.exe" "%1") from the shell. Ok, it works, but the working dir is always "c:". I would like to tell Windows that when opening a file from the shell the working dir is "c:/programs dir/my app dir". A solution could be to write in the code SetCurrentDir(GetExeDirectory()), but doing so it would be impossible to use another working dir... Any suggestion? thanks
-
I inserted in the registry (HKCR/myappdata/shell/open) the command line to open a file ("c:/programs dir/my app dir/myapp.exe" "%1") from the shell. Ok, it works, but the working dir is always "c:". I would like to tell Windows that when opening a file from the shell the working dir is "c:/programs dir/my app dir". A solution could be to write in the code SetCurrentDir(GetExeDirectory()), but doing so it would be impossible to use another working dir... Any suggestion? thanks
In your app, in the initial Update, get the command line, parse for the .exe (or use the command line parser from CP, make a search about it), get the next string after the exe, here you have the path to your file. put a SetCurrentDir(str_commandline_file); You'ra done. ~RaGE();
-
In your app, in the initial Update, get the command line, parse for the .exe (or use the command line parser from CP, make a search about it), get the next string after the exe, here you have the path to your file. put a SetCurrentDir(str_commandline_file); You'ra done. ~RaGE();
I don't need the file path, I want that the working path is the same of the exe. But I can't encode that in the source code, I must say that to she shell...
-
I inserted in the registry (HKCR/myappdata/shell/open) the command line to open a file ("c:/programs dir/my app dir/myapp.exe" "%1") from the shell. Ok, it works, but the working dir is always "c:". I would like to tell Windows that when opening a file from the shell the working dir is "c:/programs dir/my app dir". A solution could be to write in the code SetCurrentDir(GetExeDirectory()), but doing so it would be impossible to use another working dir... Any suggestion? thanks
What you want cannot be done. When you associate a file-type with a program, you provide an absolute path to the EXE responsible for it. How else do you think Windows is going to know how to find it? You could, however, get away with just putting the name of the EXE in the registry, and then making sure the EXE can be found via the PATH environment variable. Sloppy, but do-able.
-
I don't need the file path, I want that the working path is the same of the exe. But I can't encode that in the source code, I must say that to she shell...
You caught me wrong. Assume the user, when installing your tool, put it in F:\Apps\Mytool\Tool.exe, and registers your associated files with extension .paolo. Then, he opens an explorer, doubleclicks on myfile.paolo which is in C:\CurrentFiles. So your command line, sent from the shell to the code, is : F:\Apps\Mytool\Tool.exe C:\CurrentFiles\myfile.paolo So now you can retrieve the exe path, and use
SetDirectory()
~RaGE(); -
You caught me wrong. Assume the user, when installing your tool, put it in F:\Apps\Mytool\Tool.exe, and registers your associated files with extension .paolo. Then, he opens an explorer, doubleclicks on myfile.paolo which is in C:\CurrentFiles. So your command line, sent from the shell to the code, is : F:\Apps\Mytool\Tool.exe C:\CurrentFiles\myfile.paolo So now you can retrieve the exe path, and use
SetDirectory()
~RaGE();That could be a good solution, but I can't get the full command line... The variable m_lpCmdLine only contains "C:\CurrentFiles\myfile.paolo" without "F:\Apps\Mytool\Tool.exe" :(
-
That could be a good solution, but I can't get the full command line... The variable m_lpCmdLine only contains "C:\CurrentFiles\myfile.paolo" without "F:\Apps\Mytool\Tool.exe" :(
In InitInstance() :
CString str=GetCommandLine();
In fact, m_lpCmdLine contains only the parameters. Check this in the MSDN for more info, i give you just the remark here : Remarks: ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type. ~RaGE();
-
In InitInstance() :
CString str=GetCommandLine();
In fact, m_lpCmdLine contains only the parameters. Check this in the MSDN for more info, i give you just the remark here : Remarks: ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type. ~RaGE();
Thank you!!! It was so obvious, that I couldn't find it :)