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. execute an app from code

execute an app from code

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
7 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.
  • B Offline
    B Offline
    BlackDice
    wrote on last edited by
    #1

    I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond

    T E 2 Replies Last reply
    0
    • B BlackDice

      I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond

      T Offline
      T Offline
      T1TAN
      wrote on last edited by
      #2

      hi, in c++ you also use ShellExecute(), and it is quite easy to use, here is the online MSDN link i found: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp --- kick ash. http://sprdsoft.bigmoron.com http://t1tan.cjb.net

      B 1 Reply Last reply
      0
      • B BlackDice

        I have an app that I want to run (dtsrun.exe) I can run it from the command line, but how do I do that in code with the specified switches? I know in vb I could use the ShellExecute() function, but how do I do that in C++ if I want to run this: 'dtsrun /S localhost /p jt'? thanks in advance for any help!! If it's broken, I probably did it bdiamond

        E Offline
        E Offline
        Ed K
        wrote on last edited by
        #3

        Don't remember where I picked this up but most likely somewhere here...Best site around!!BOOL LaunchChild(LPCSTR lpszCmdLine, BOOL bShowChildWindow) { HANDLE hProcess = ::GetCurrentProcess(); PROCESS_INFORMATION pi; // Set up the start up info struct. STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; // Note that dwFlags must include STARTF_USESHOWWINDOW to // use the wShowWindow flags. si.wShowWindow = bShowChildWindow ? SW_SHOW: SW_HIDE; // Create the NULL security token for the process LPVOID lpSD = NULL; LPSECURITY_ATTRIBUTES lpSA = NULL; lpSD = ::GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); ::InitializeSecurityDescriptor(lpSD, SECURITY_DESCRIPTOR_REVISION); ::SetSecurityDescriptorDacl(lpSD, -1, 0, 0); lpSA = (LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR, sizeof(SECURITY_ATTRIBUTES)); lpSA->nLength = sizeof(SECURITY_ATTRIBUTES); lpSA->lpSecurityDescriptor = lpSD; lpSA->bInheritHandle = TRUE; // Try to spawn the process. BOOL bResult = ::CreateProcess(NULL, (LPTSTR)(LPCTSTR)lpszCmdLine, lpSA, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); // Cleanup memory allocation if (lpSA != NULL) ::GlobalFree(lpSA); if (lpSD != NULL) ::GlobalFree(lpSD); // Return if an error occurs. if (!bResult) return FALSE; // Close the handles to reduce kernal usage count ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess); // return true return bResult; }
        Just pass in the command line and whether or not you want the console window displayed. Thanks to whomever submitted this! ed The absence of evidence is not evidence of absence.

        B 1 Reply Last reply
        0
        • T T1TAN

          hi, in c++ you also use ShellExecute(), and it is quite easy to use, here is the online MSDN link i found: http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp --- kick ash. http://sprdsoft.bigmoron.com http://t1tan.cjb.net

          B Offline
          B Offline
          BlackDice
          wrote on last edited by
          #4

          THANKS!! That worked perfectly If it's broken, I probably did it bdiamond

          1 Reply Last reply
          0
          • E Ed K

            Don't remember where I picked this up but most likely somewhere here...Best site around!!BOOL LaunchChild(LPCSTR lpszCmdLine, BOOL bShowChildWindow) { HANDLE hProcess = ::GetCurrentProcess(); PROCESS_INFORMATION pi; // Set up the start up info struct. STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; // Note that dwFlags must include STARTF_USESHOWWINDOW to // use the wShowWindow flags. si.wShowWindow = bShowChildWindow ? SW_SHOW: SW_HIDE; // Create the NULL security token for the process LPVOID lpSD = NULL; LPSECURITY_ATTRIBUTES lpSA = NULL; lpSD = ::GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); ::InitializeSecurityDescriptor(lpSD, SECURITY_DESCRIPTOR_REVISION); ::SetSecurityDescriptorDacl(lpSD, -1, 0, 0); lpSA = (LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR, sizeof(SECURITY_ATTRIBUTES)); lpSA->nLength = sizeof(SECURITY_ATTRIBUTES); lpSA->lpSecurityDescriptor = lpSD; lpSA->bInheritHandle = TRUE; // Try to spawn the process. BOOL bResult = ::CreateProcess(NULL, (LPTSTR)(LPCTSTR)lpszCmdLine, lpSA, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); // Cleanup memory allocation if (lpSA != NULL) ::GlobalFree(lpSA); if (lpSD != NULL) ::GlobalFree(lpSD); // Return if an error occurs. if (!bResult) return FALSE; // Close the handles to reduce kernal usage count ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess); // return true return bResult; }
            Just pass in the command line and whether or not you want the console window displayed. Thanks to whomever submitted this! ed The absence of evidence is not evidence of absence.

            B Offline
            B Offline
            BlackDice
            wrote on last edited by
            #5

            thanks ed, but the answer I got before yours worked perfectly and it only uses one line:

            ShellExecute(NULL,"open","dtsrun.exe","/S localhost /U admin /P admin /N ImportDistTextToTable",NULL,SW_HIDE);
            

            If it's broken, I probably did it bdiamond

            S 1 Reply Last reply
            0
            • B BlackDice

              thanks ed, but the answer I got before yours worked perfectly and it only uses one line:

              ShellExecute(NULL,"open","dtsrun.exe","/S localhost /U admin /P admin /N ImportDistTextToTable",NULL,SW_HIDE);
              

              If it's broken, I probably did it bdiamond

              S Offline
              S Offline
              Snyp
              wrote on last edited by
              #6

              Actually his way defines the whole function... good way to learn... and his function takes in less parameters and too could be in one line of code :) Actual Linux Penguins were harmed in the creation of this message.

              T 1 Reply Last reply
              0
              • S Snyp

                Actually his way defines the whole function... good way to learn... and his function takes in less parameters and too could be in one line of code :) Actual Linux Penguins were harmed in the creation of this message.

                T Offline
                T Offline
                Tim Smith
                wrote on last edited by
                #7

                But it also requires an NT kernel operating system. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                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