Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:50:27+00:00 2026-05-15T16:50:27+00:00

Related question: CreateProcess doesn't pass command line arguments . Is there a difference between

  • 0

Related question: CreateProcess doesn't pass command line arguments.

Is there a difference between passing an argument vs. passing a parameter to an EXE when using CreateProcess (and/or ShellExecuteEx)?

I’m trying to call something like:

myExe.exe /myparam

with the code like :

TCHAR Buffer[MAX_PATH];
 DWORD dwRet;
 dwRet = GetCurrentDirectory(MAX_PATH, Buffer);

 CString sCmd;
 sCmd.Format ( "%s\\%s", Buffer, command);
 CString sParam( "/myparam" );
 sCmd += " " + sParam;

 STARTUPINFO si;
 PROCESS_INFORMATION pi;

 ZeroMemory( &si, sizeof(si) );
 si.cb = sizeof(si);
 ZeroMemory( &pi, sizeof(pi) );


 if (CreateProcess( NULL, sCmd.GetBuffer() , NULL, NULL, TRUE, 0, NULL, Buffer, &si, &pi))
 {
  ::WaitForSingleObject(pi.hProcess, INFINITE);
  CloseHandle(pi.hProcess);
  CloseHandle(pi.hThread);
 }
 else
 {
  LPVOID lpMsgBuf = NULL;
  DWORD dw = GetLastError(); 

  FormatMessage(
   FORMAT_MESSAGE_ALLOCATE_BUFFER | 
   FORMAT_MESSAGE_FROM_SYSTEM |
   FORMAT_MESSAGE_IGNORE_INSERTS,
   NULL,
   dw,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   (LPTSTR) &lpMsgBuf,
   0, NULL );

  CString msg;
  msg.Format("Failed to start command line (error: %s) : %s\n",lpMsgBuf,sCmd);

  AfxMessageBox(msg); 

  LocalFree(lpMsgBuf);
 }

From what I understand from the other thread and MSDN is that it should be working properly and call the EXE with the parameter; doing the above code without adding the “/myparam” works like it should.

I’ve tried the EXE from the command line and from Explorer (by creating a shortcut and adding /myparam to the target name) and it’s working alright.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:50:28+00:00Added an answer on May 15, 2026 at 4:50 pm

    Try this in case there are spaces in the path:

    CString sCmd;
    sCmd.Format ( "\"%s\\%s\"", Buffer, command);
    

    Or else pass the parameters via the parameters argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's a very related question: Create List<CustomObject> from List<string> however it doesn't deal with
There is another possibly related question on this but it didn't have answers and
There's a related question What is the preferred Java XML binding framework? In the
there is lot of related question but I can't figured out... link to emacs
NOTE: I have a related question here (http://stackoverflow.com/questions/6915055/are-jsf-views-shared-between-users) but that deals with a few
Related question [stackoverflow] here . I'm trying to do the above, but I want
Related question, about assignment-initialization-declaration. $ javac MatchTest.java MatchTest.java:7: ')' expected for((int i=-1 && String
This question is an extension of this Related question . Taking Derick's advice, I
I posted a related question to no response but here I'll be less narrow.
This is a related question to this but with EXISTS instead of IN SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.