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

ShellExecute Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 Posts 5 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.
  • L Offline
    L Offline
    LFK_Michael
    wrote on last edited by
    #1

    Hello Everybody, I hope i have choosen the right forum for my Question. I have a little application which starts another programm with a specific path (a txt-file). Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works. So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ? Thanks in advance, Michael

    L M A 3 Replies Last reply
    0
    • L LFK_Michael

      Hello Everybody, I hope i have choosen the right forum for my Question. I have a little application which starts another programm with a specific path (a txt-file). Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works. So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ? Thanks in advance, Michael

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to show the section of the code that tries to start the program and explain exactly what part of it is not working.

      L 1 Reply Last reply
      0
      • L Lost User

        You need to show the section of the code that tries to start the program and explain exactly what part of it is not working.

        L Offline
        L Offline
        LFK_Michael
        wrote on last edited by
        #3

        void StartEXE (String^ path)
        {
        TCHAR prog[] = TEXT("C:\\...\\...."); // Programpath

        string p ;
        MarshalString(path, p);
        std::string str= p;
        TCHAR *param=new TCHAR[str.size()+1];
        param[str.size()]=0;

        const TCHAR open[] = TEXT("runas")
        ShellExecute( NULL, open, prog, param, NULL, SW_SHOWNORMAL );
        }

        void MarshalString ( String ^ s, string& os )
        {
        using namespace Runtime::InteropServices;
        const char* chars =
        (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
        os = chars;
        Marshal::FreeHGlobal(IntPtr((void*)chars));
        }

        This is the code i use. I call StartEXE with a String like C:\\test.txt , the programmpath is fix in the code. The Programm i want to open opens but it don´t open the path. This happens only by one Programm, if i want to open another programm this code works. Any Ideas?

        L D 2 Replies Last reply
        0
        • L LFK_Michael

          void StartEXE (String^ path)
          {
          TCHAR prog[] = TEXT("C:\\...\\...."); // Programpath

          string p ;
          MarshalString(path, p);
          std::string str= p;
          TCHAR *param=new TCHAR[str.size()+1];
          param[str.size()]=0;

          const TCHAR open[] = TEXT("runas")
          ShellExecute( NULL, open, prog, param, NULL, SW_SHOWNORMAL );
          }

          void MarshalString ( String ^ s, string& os )
          {
          using namespace Runtime::InteropServices;
          const char* chars =
          (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
          os = chars;
          Marshal::FreeHGlobal(IntPtr((void*)chars));
          }

          This is the code i use. I call StartEXE with a String like C:\\test.txt , the programmpath is fix in the code. The Programm i want to open opens but it don´t open the path. This happens only by one Programm, if i want to open another programm this code works. Any Ideas?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Without seeing the actual parameters and the code of the executing program it's impossible to guess what may be happening. It would probably be a good idea to add some debug code to the called program so you can see exactly what parameters it is trying to deal with. What is the "runas" parameter supposed to do?

          1 Reply Last reply
          0
          • L LFK_Michael

            Hello Everybody, I hope i have choosen the right forum for my Question. I have a little application which starts another programm with a specific path (a txt-file). Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works. So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ? Thanks in advance, Michael

            M Offline
            M Offline
            Marius Bancila
            wrote on last edited by
            #5

            That should only work if the application you want to start supports command line parameters, or if it the default application for starting the document type you're trying to open.

            L 1 Reply Last reply
            0
            • L LFK_Michael

              void StartEXE (String^ path)
              {
              TCHAR prog[] = TEXT("C:\\...\\...."); // Programpath

              string p ;
              MarshalString(path, p);
              std::string str= p;
              TCHAR *param=new TCHAR[str.size()+1];
              param[str.size()]=0;

              const TCHAR open[] = TEXT("runas")
              ShellExecute( NULL, open, prog, param, NULL, SW_SHOWNORMAL );
              }

              void MarshalString ( String ^ s, string& os )
              {
              using namespace Runtime::InteropServices;
              const char* chars =
              (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
              os = chars;
              Marshal::FreeHGlobal(IntPtr((void*)chars));
              }

              This is the code i use. I call StartEXE with a String like C:\\test.txt , the programmpath is fix in the code. The Programm i want to open opens but it don´t open the path. This happens only by one Programm, if i want to open another programm this code works. Any Ideas?

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

              You might also want to consider asking for help here.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              1 Reply Last reply
              0
              • M Marius Bancila

                That should only work if the application you want to start supports command line parameters, or if it the default application for starting the document type you're trying to open.

                L Offline
                L Offline
                LFK_Michael
                wrote on last edited by
                #7

                Thats what i wanted to hear :) The "runas" is to start a exe with admin rights. Is it right that open a Programm with ShellExecute is different to Drag&Drop way ? Because if i drag and drop a textfile on the Program i want to open it works. btw the program is a finished one done not by myself. Is there a way to drag&drop the textfile to the program via code?

                M 1 Reply Last reply
                0
                • L LFK_Michael

                  Thats what i wanted to hear :) The "runas" is to start a exe with admin rights. Is it right that open a Programm with ShellExecute is different to Drag&Drop way ? Because if i drag and drop a textfile on the Program i want to open it works. btw the program is a finished one done not by myself. Is there a way to drag&drop the textfile to the program via code?

                  M Offline
                  M Offline
                  Marius Bancila
                  wrote on last edited by
                  #8

                  Starting a program by command line and drag&drop are different things. An application can implement any (or neither). You cannot simulate drag&drop from code if that application is not handling the drop.

                  L 1 Reply Last reply
                  0
                  • M Marius Bancila

                    Starting a program by command line and drag&drop are different things. An application can implement any (or neither). You cannot simulate drag&drop from code if that application is not handling the drop.

                    L Offline
                    L Offline
                    LFK_Michael
                    wrote on last edited by
                    #9

                    Thank you for the answer. The Application i want to open supports drag&drop. How can i implement the drag&drop function in my program? Do you have any Ideas ?

                    1 Reply Last reply
                    0
                    • L LFK_Michael

                      Hello Everybody, I hope i have choosen the right forum for my Question. I have a little application which starts another programm with a specific path (a txt-file). Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works. So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ? Thanks in advance, Michael

                      A Offline
                      A Offline
                      Albert Holguin
                      wrote on last edited by
                      #10

                      Not exactly sure what may be causing your problem... but the unix/linux calls (also supported by Windows) usually work pretty well for me. Try them out (required header is in documentation)... spawn[^] exec[^]

                      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