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. CreateProcess doesn’t passes command line arguments [modified]

CreateProcess doesn’t passes command line arguments [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpcomhostingtutorial
9 Posts 6 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.
  • S Offline
    S Offline
    staticv
    wrote on last edited by
    #1

    Hello I have the following code but it isn't working as expected, can't figure out what the problem is. Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments What am I doing wrong here??

    int main(int argc, char* argv[])
    {
    PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

    STARTUPINFO StartupInfo; //This is an \[in\] parameter
    
    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
    StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
    
    LPTSTR cmdArgs = "name@example.com";
    
    if(CreateProcess("D:\\\\email\\\\smtp.exe", cmdArgs, 
        NULL,NULL,FALSE,0,NULL,
        NULL,&StartupInfo,&ProcessInfo))
    { 
        WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
    
        printf("Yohoo!");
    }  
    else
    {
        printf("The process could not be started...");
    }
    
    return 0;
    

    }

    Hey one more thing, if I pass my cmdArgs like this:

    // a space as the first character
    LPTSTR cmdArgs = " manzoor10@gmail.com";

    I get the error:

    Object reference not set to an instance of an object

    then CreateProcess returns TRUE but my target process isn't executed.

    Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

    modified on Thursday, June 10, 2010 2:13 AM

    F M S T 4 Replies Last reply
    0
    • S staticv

      Hello I have the following code but it isn't working as expected, can't figure out what the problem is. Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments What am I doing wrong here??

      int main(int argc, char* argv[])
      {
      PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

      STARTUPINFO StartupInfo; //This is an \[in\] parameter
      
      ZeroMemory(&StartupInfo, sizeof(StartupInfo));
      StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
      
      LPTSTR cmdArgs = "name@example.com";
      
      if(CreateProcess("D:\\\\email\\\\smtp.exe", cmdArgs, 
          NULL,NULL,FALSE,0,NULL,
          NULL,&StartupInfo,&ProcessInfo))
      { 
          WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
          CloseHandle(ProcessInfo.hThread);
          CloseHandle(ProcessInfo.hProcess);
      
          printf("Yohoo!");
      }  
      else
      {
          printf("The process could not be started...");
      }
      
      return 0;
      

      }

      Hey one more thing, if I pass my cmdArgs like this:

      // a space as the first character
      LPTSTR cmdArgs = " manzoor10@gmail.com";

      I get the error:

      Object reference not set to an instance of an object

      then CreateProcess returns TRUE but my target process isn't executed.

      Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

      modified on Thursday, June 10, 2010 2:13 AM

      F Offline
      F Offline
      Franck Paquier
      wrote on last edited by
      #2

      good morning Not sure it will solve your problem but did you notice that lpCommandLine is an in out parameter ? in MSDN Help i found the following information: The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation. Hope this will help. Regards Franck

      1 Reply Last reply
      0
      • S staticv

        Hello I have the following code but it isn't working as expected, can't figure out what the problem is. Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments What am I doing wrong here??

        int main(int argc, char* argv[])
        {
        PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

        STARTUPINFO StartupInfo; //This is an \[in\] parameter
        
        ZeroMemory(&StartupInfo, sizeof(StartupInfo));
        StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
        
        LPTSTR cmdArgs = "name@example.com";
        
        if(CreateProcess("D:\\\\email\\\\smtp.exe", cmdArgs, 
            NULL,NULL,FALSE,0,NULL,
            NULL,&StartupInfo,&ProcessInfo))
        { 
            WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
            CloseHandle(ProcessInfo.hThread);
            CloseHandle(ProcessInfo.hProcess);
        
            printf("Yohoo!");
        }  
        else
        {
            printf("The process could not be started...");
        }
        
        return 0;
        

        }

        Hey one more thing, if I pass my cmdArgs like this:

        // a space as the first character
        LPTSTR cmdArgs = " manzoor10@gmail.com";

        I get the error:

        Object reference not set to an instance of an object

        then CreateProcess returns TRUE but my target process isn't executed.

        Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

        modified on Thursday, June 10, 2010 2:13 AM

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #3

        This: http://bobmoore.mvps.org/Win32/w32tip46.htm[^] may give you some insight but I'm not sure. I always use CreateProcess by concatenating the app name and the arguments and set this as the second parameter (first parameter set to NULL) and it has never failed.

        1 Reply Last reply
        0
        • S staticv

          Hello I have the following code but it isn't working as expected, can't figure out what the problem is. Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments What am I doing wrong here??

          int main(int argc, char* argv[])
          {
          PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

          STARTUPINFO StartupInfo; //This is an \[in\] parameter
          
          ZeroMemory(&StartupInfo, sizeof(StartupInfo));
          StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
          
          LPTSTR cmdArgs = "name@example.com";
          
          if(CreateProcess("D:\\\\email\\\\smtp.exe", cmdArgs, 
              NULL,NULL,FALSE,0,NULL,
              NULL,&StartupInfo,&ProcessInfo))
          { 
              WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
              CloseHandle(ProcessInfo.hThread);
              CloseHandle(ProcessInfo.hProcess);
          
              printf("Yohoo!");
          }  
          else
          {
              printf("The process could not be started...");
          }
          
          return 0;
          

          }

          Hey one more thing, if I pass my cmdArgs like this:

          // a space as the first character
          LPTSTR cmdArgs = " manzoor10@gmail.com";

          I get the error:

          Object reference not set to an instance of an object

          then CreateProcess returns TRUE but my target process isn't executed.

          Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

          modified on Thursday, June 10, 2010 2:13 AM

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          I suspect your command-line argument is being interpreted as the executable name. See the CreateProcess[^] documentation:

          Console processes written in C can use the argc and argv arguments to parse the command line. Because argv[0] is the module name, C programmers generally repeat the module name as the first token in the command line.

          While that's talking about C programs, .NET programs conform to that as well. Add an argument before the e-mail address and you should find it all works.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          1 Reply Last reply
          0
          • S staticv

            Hello I have the following code but it isn't working as expected, can't figure out what the problem is. Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments What am I doing wrong here??

            int main(int argc, char* argv[])
            {
            PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

            STARTUPINFO StartupInfo; //This is an \[in\] parameter
            
            ZeroMemory(&StartupInfo, sizeof(StartupInfo));
            StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
            
            LPTSTR cmdArgs = "name@example.com";
            
            if(CreateProcess("D:\\\\email\\\\smtp.exe", cmdArgs, 
                NULL,NULL,FALSE,0,NULL,
                NULL,&StartupInfo,&ProcessInfo))
            { 
                WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
                CloseHandle(ProcessInfo.hThread);
                CloseHandle(ProcessInfo.hProcess);
            
                printf("Yohoo!");
            }  
            else
            {
                printf("The process could not be started...");
            }
            
            return 0;
            

            }

            Hey one more thing, if I pass my cmdArgs like this:

            // a space as the first character
            LPTSTR cmdArgs = " manzoor10@gmail.com";

            I get the error:

            Object reference not set to an instance of an object

            then CreateProcess returns TRUE but my target process isn't executed.

            Top Web Hosting Providers[^] Do, or do not. There is no 'try'.

            modified on Thursday, June 10, 2010 2:13 AM

            T Offline
            T Offline
            tns_ranjith
            wrote on last edited by
            #5

            PROCESS_INFORMATION pi; ZeroMemory (&pi, sizeof (pi)); STARTUPINFOA si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; //si.wShowWindow = SW_HIDE; si.wShowWindow = SW_SHOW; CreateProcessA (NULL, cmd, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi);

            M 1 Reply Last reply
            0
            • T tns_ranjith

              PROCESS_INFORMATION pi; ZeroMemory (&pi, sizeof (pi)); STARTUPINFOA si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; //si.wShowWindow = SW_HIDE; si.wShowWindow = SW_SHOW; CreateProcessA (NULL, cmd, 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &si, &pi);

              M Offline
              M Offline
              Michael Schubert
              wrote on last edited by
              #6

              tns_ranjith wrote:

              STARTUPINFOA

              tns_ranjith wrote:

              CreateProcessA

              Why?

              R T 2 Replies Last reply
              0
              • M Michael Schubert

                tns_ranjith wrote:

                STARTUPINFOA

                tns_ranjith wrote:

                CreateProcessA

                Why?

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                You shouldn't be giving him any importance (take a look at some of his recent posts). You could just mark it down instead.

                It is a crappy thing, but it's life -^ Carlo Pallini

                M 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  You shouldn't be giving him any importance (take a look at some of his recent posts). You could just mark it down instead.

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  M Offline
                  M Offline
                  Michael Schubert
                  wrote on last edited by
                  #8

                  Oh, I thought he was trying to make a point.

                  1 Reply Last reply
                  0
                  • M Michael Schubert

                    tns_ranjith wrote:

                    STARTUPINFOA

                    tns_ranjith wrote:

                    CreateProcessA

                    Why?

                    T Offline
                    T Offline
                    tns_ranjith
                    wrote on last edited by
                    #9

                    for unicode project u want to use non unicode characters support..

                    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