CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2001
    Posts
    306

    CreateProcess failed with ERROR_ACCESS_DENIED

    Hello,

    big problem:
    on an users system my app's call to CreateProcess failed with ERROR_ACCESS_DENIED.
    What are possible reasons?!
    I have no idea.

    My call:
    Code:
    CreateProcess(NULL,buffy,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
    thx.
    Ralf

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    1. From your "code snippet" is unclear what API call produces this "access denied" error: CreateProcess or some other one.
    2. What is "buffy"?
    3. What is this process supposed to do?
    4. In what OS did this call produce the ERROR_ACCESS_DENIED? If it was Vista and above - ask your user to switch off the UAC or run as admin.
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Your code in post #1 doesn't show any error detection - so how are you knowing that it failed with error 5?

    How do you initialize si?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    win10, 64-bit. Sorry.
    It is ::CreateProcess and buffy is the commandline which holds the name of the calling app. The calling app is also from me and creates a new window to show something.

  5. #5
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    @2kaud:
    my snippet shows only the call.
    I do it with
    if(::CreateProcess(...))
    {
    ..
    }
    else
    {
    // error
    // ask for GetLastError() !!!!
    }

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    You need to initialise si before the call. Consider
    Code:
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    
        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
    
        ZeroMemory( &pi, sizeof(pi) );
    
        if (::CreateProcess(...))
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Hello,

    si was initialize exactly like in your snippet.
    pi not, but why?
    pi is an output parameter, it should be filled by CreateProcess.

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    There is no absolute requirement to initialise pi in this instance because as you say it is filled by CreateProcess(). However, I always like to initialise any variable/structure. I would usually do it as part of the variable definition as below (I copied the code in post #6 from MSDN).

    This example creates an instance of explorer and works on my Win10/64bit system.

    Code:
    #include <Windows.h>
    #include <iostream>
    
    int main()
    {
    	char cmd[] = "explorer.exe";
    
    	STARTUPINFO si = { sizeof(si), 0 };
    	PROCESS_INFORMATION pi = { 0 };
    
    	if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
    		std::cout << "Create failure. Error " << GetLastError() << std::endl;
    	else
    		std::cout << "Create success!" << std::endl;
    
    	return system("pause()");
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Quote Originally Posted by Ralf Schneider View Post
    win10, 64-bit. Sorry.
    It is ::CreateProcess and buffy is the commandline which holds the name of the calling app. The calling app is also from me and creates a new window to show something.
    1. What happens if the user just starts this "calling app"? Does it work or fail?
    2. Again: UAC & "or run as admin" - ?
    Victor Nijegorodov

  10. #10
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    waiting for an answer from the user....

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Quote Originally Posted by Ralf Schneider View Post
    waiting for an answer from the user....
    How about adding some logging to your app and write out the parameters that are passed in to CreateProcess (cp) to the log file? You can gather pretty much everything (including what access the user has) and record it in the logfile. Then the user only has to send you the logfile. You can also use the runas verb and shell execute in cp to prompt the user to allow elevated permissions. Lastly, when the user passes in the app in the command line, do they pass in the full path to the app? In not, is the app in the user's or system path? If the user passes in the path, does the path contain spaces, and if so, does the user quote the path?

  12. #12
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Hello Arjay,

    all the parameters of cp are in my hands.
    There is nothing that can be influenced by the user.
    The calling app is in the same program-folder as the caller app with absolute path.

  13. #13
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    on an users system
    Does this mean that your app works on other Win10 systems but fails only on one?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  14. #14
    Join Date
    Jul 2001
    Posts
    306

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Quote Originally Posted by 2kaud View Post
    Does this mean that your app works on other Win10 systems but fails only on one?
    yes.

  15. #15
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CreateProcess failed with ERROR_ACCESS_DENIED

    Quote Originally Posted by Ralf Schneider View Post
    Hello Arjay,

    all the parameters of cp are in my hands.
    There is nothing that can be influenced by the user.
    The calling app is in the same program-folder as the caller app with absolute path.
    What can be different is the account your program is running under and the setting on the user's machine. It also depends on what the program that you are attempting to launch does and needs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured