1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CreateProcess help...

Discussion in 'C' started by dcer, Oct 21, 2007.

  1. dcer

    dcer New Member

    Joined:
    Oct 21, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    hi,

    want i want to do is, when u right click a shortcut > and in target, it is "PROGRAM PATH"...and u can put "PROGRAM PATH" /cmd /cmd2

    how would i do that in CreateProcess() function?
    Code:
     CreateProcess("C\\program.exe /say hello",
     NULL,
     NULL,
     NULL,
     FALSE,
     0,
     NULL,
     NULL,
     &s,
     &p);
    
    how would u do that?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Second parameter is the command line you want to pass to the exe.
     
  3. dcer

    dcer New Member

    Joined:
    Oct 21, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    it seem to doesn't work -_-...in order to CreateProcess, the EXE must have /load /config test2 to load the config file when the exe opens...here's CreateProcess:

    Code:
     CreateProcess("C:\\configeditor\\ceditor.exe",
     "/load /config defaultc",
     NULL,
     NULL,
     FALSE,
     0,
     NULL,
     NULL,
     &s,
     &p);
    
    and i've tried:
    Code:
     CreateProcess("C:\\configeditor\\ceditor.exe /load /config defaultc",
     NULL,
     NULL,
     NULL,
     FALSE,
     0,
     NULL,
     NULL,
     &s,
     &p);
    
    it doesn't seem to be doing what i want it to do..because it displays an error "Config needs to be loaded.."
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Just check ceditor if it supports the command line you are providing because createprocess is a tried and tested over time and there is nothing you can do where the API can go wrong and all you need to be doing is pass the parameters correctly.
     
  5. dcer

    dcer New Member

    Joined:
    Oct 21, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    i am positive because i entered it in the TARGET(shortcut >properties) and in start >run "PROGRAM" /load /config defaultc

    i write a test program in autoit...
    http://www.wikifortio.com/165615/test.zip

    unzip and write in start > run "PATH TO test.exe" hello...it will display a msgbox "HELLO TGHERE"
    i tried doing with CreateProcess..it doesn't work

    Code:
    CreateProcess("C:\\test.exe",
     "hello",
     NULL,
     NULL,
     FALSE,
     0,
     NULL,
     NULL,
     &s,
     &p);
    
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    The code below works for me
    Code:
        STARTUPINFO	si;
        PROCESS_INFORMATION pi;
    	
        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );
    	
        // Start the child process. 
        BOOL bRetVal = ::CreateProcess( "Exe Path",			  
    		(LPSTR)((LPCTSTR)szCommandLine),	  // Command line. 
    		NULL,             // Process handle not inheritable. 
    		NULL,             // Thread handle not inheritable. 
    		FALSE,            // Set handle inheritance to FALSE. 
    		0,                // No creation flags. 
    		NULL,             // Use parent's environment block. 
    		NULL,             // Use parent's starting directory. 
    		&si,              // Pointer to STARTUPINFO structure.
    		&pi               // Pointer to PROCESS_INFORMATION structure.
    	);
    
     
  7. dcer

    dcer New Member

    Joined:
    Oct 21, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    like this?

    Code:
     CreateProcess("C:\\test.exe",
     (LPSTR)((LPCTSTR)"hello"),
     NULL,
     NULL,
     FALSE,
     0,
     NULL,
     NULL,
     &s,
     &p);
    
    if it is, it doesn't work. =\
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Try running my code and if it does not work you should be exploring the areas where you API work correctly.
     

Share This Page