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 8104043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:43:23+00:00 2026-06-05T23:43:23+00:00

I’m having a little confusion due to conflicting return values from CreateProcess() and GetLastError()

  • 0

I’m having a little confusion due to conflicting return values from CreateProcess() and GetLastError(). When I use CreateProcess() in a manner similar to below, it succeeds and appears to accomplish its required tasks. Yet, GetLastError() still returns Access is Denied.

If access is denied, why is does it appear to complete the task. In contrast, if CreateProcess() succeeds, why is GetLastError() returning access denied?

Or is my use of GetLastError() incorrect? Am I only supposed to use it when CreateProcess() returns a failed value? (My justification for the below behavior was that I figured it was better to be safe than sorry)

    SetLastError(0);
    hello = CreateProcess(_T("C:\\Windows\\System32\\cmd.exe"), 
        _T("C:\\Windows\\System32\\cmd.exe /C ant debug"),
        NULL,NULL,false,0,NULL,
        _T("C:\\My\\Directory"),&siStartupInfo, &piProcessInfo);
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ALLOCATE_BUFFER 
        |FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(), 
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
        (LPTSTR)&errorText, 0, NULL); 
    AfxMessageBox(errorText);

Is this type of behavior normal? In the CreateProcess() documentation, it mentions using GetLastError() when CreateProcess() fails, but it does not mention the inverse. Not criticizing the documentation, would just like some clarification.

This occurs whether the second parameter in CreateProcess() is NULL or not. Maybe it has to do with cmd.exe permissions? If that’s the case, shouldn’t CreateProcess() fail? Thank you.

  • 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-06-05T23:43:25+00:00Added an answer on June 5, 2026 at 11:43 pm

    From the documentation of GetLastError

    The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread’s last-error code set it when they fail. However, some functions also set the last-error code when they succeed. [emphasis mine]

    I think you get the experienced outcome because, uppon success, CreateProcess does not set the error value GetLastError returns. Instead your call to GetLastError returns an error set by another function called earlier

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.