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

  • SEARCH
  • Home
  • 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 187863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:53:58+00:00 2026-05-11T15:53:58+00:00

I would like a Win32 process to launch an external script and be able

  • 0

I would like a Win32 process to launch an external script and be able to retrieve the ERRORLEVEL that it returns.

The other way around is quite easy. Just use exit(errorcode) or return errorcode; in your Win32 app and the calling script gets its ERRORLEVEL value set properly.

But, from a Win32 calling application, getting the script errorcode is not quite the same.

I tried using CreateProcess() and calling GetExitCodeProcess(), but it always returns 0 and not the actual value of ERRORLEVEL. Even if I end my called script with exit %ERRORLEVEL%

My best guess is that a script is not a process per-say. Most probably CMD.EXE is running instead and most likely always ending with a ExitCode of 0. I know that ERRORLEVEL is not the same as the process ExitCode value, I would have hoped that CMD.EXE would have mirrored it.

EDIT:

Sorry I asked! I just found MY problem. I was using exit /b errorcode instead of exit errorcode in my batch file. It seems that the /b options has the advantage of only closing the running script, not CMD.EXE when you are testing from command line. But the disadvantage of not setting the proper ExitCode for CMD.EXE.

So, for posterity what I am doing is:

int LaunchScript(TCHAR *pCmdLineParam) {     bool bResult;     PROCESS_INFORMATION pi;     STARTUPINFO si;      memset(&si, 0, sizeof(si));     si.cb = sizeof(si);      TCHAR   cmdLine[256];     _tcscpy(cmdLine,L'Test.cmd');     _tcscat(cmdLine,L' ');     _tcscat(cmdLine,pCmdLineParam);      _tprintf(L'Process executing: %s\n',cmdLine);      bResult = CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)?true:false;     if (!bResult) {         _tprintf(L'CreateProcess() error - %d', GetLastError());         return -1;     }      DWORD result = WaitForSingleObject(pi.hProcess,15000);     if( result == WAIT_TIMEOUT ) {         return -2;     }      DWORD exitCode=0;     if( !GetExitCodeProcess(pi.hProcess,&exitCode) ) {         _tprintf(L'GetExitCodeProcess() error - %d', GetLastError());         return -1;     }      _tprintf(L'Process exitcode=%d\n',exitCode);      return exitCode; } 

My ‘entry point’ batch file looks like:

@call %* @exit %ERRORLEVEL% 

And I am passing my script to run as a parameter to the entry point script. The other ‘sub-scripts’ files can either call exit /b or exit, because everything is covered.

  • 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. 2026-05-11T15:53:59+00:00Added an answer on May 11, 2026 at 3:53 pm

    This works for me:

    int DoDOS(string parms) {  Process p=new Process(); ProcessStartInfo ProcInfo=new ProcessStartInfo();  ProcInfo.Arguments='/C '+parms; ProcInfo.CreateNoWindow=true; ProcInfo.ErrorDialog=false; ProcInfo.ErrorDialogParentHandle=IntPtr.Zero; ProcInfo.FileName='cmd.exe'; ProcInfo.RedirectStandardError=false; ProcInfo.RedirectStandardInput=false; ProcInfo.RedirectStandardOutput=false; ProcInfo.UseShellExecute=false; ProcInfo.Verb=''; ProcInfo.WindowStyle=ProcessWindowStyle.Hidden; p=Process.Start(ProcInfo);  while (!p.HasExited)       {       if (laRunning.Text!=RunningTxt) laRunning.Text=RunningTxt;       else                            laRunning.Text='';       Application.DoEvents();       Thread.Sleep(500);       }  return p.ExitCode;  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Actually, just solved it :) Problem is that SequenceT is… May 11, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer PHP does not support unsigned integers as a type, but… May 11, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer There is no way to do this in pur managed… May 11, 2026 at 7:31 pm

Related Questions

I have several slave machines and a master machine which together run a distributed
I'm developing a small utility application that needs to detect whether another one has
I would like to host an application window from a process A into the
I've seen several of answers about using Handle or Process Monitor , but I
I have an existing codebase targeting a Windows environment and with an eye to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.