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. Shell open & working dir

Shell open & working dir

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminlinuxquestion
8 Posts 3 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.
  • P Offline
    P Offline
    Paolo Vernazza
    wrote on last edited by
    #1

    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

    R D 2 Replies Last reply
    0
    • P Paolo Vernazza

      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

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      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();

      P 1 Reply Last reply
      0
      • R 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();

        P Offline
        P Offline
        Paolo Vernazza
        wrote on last edited by
        #3

        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...

        R 1 Reply Last reply
        0
        • P Paolo Vernazza

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P Paolo Vernazza

            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...

            R Offline
            R Offline
            Rage
            wrote on last edited by
            #5

            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();

            P 1 Reply Last reply
            0
            • R 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();

              P Offline
              P Offline
              Paolo Vernazza
              wrote on last edited by
              #6

              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" :(

              R 1 Reply Last reply
              0
              • P Paolo Vernazza

                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" :(

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #7

                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();

                P 1 Reply Last reply
                0
                • R 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();

                  P Offline
                  P Offline
                  Paolo Vernazza
                  wrote on last edited by
                  #8

                  Thank you!!! It was so obvious, that I couldn't find it :)

                  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