How to set BCDEdit in C++ code

天 张 1 Reputation point
2022-09-27T08:20:59.403+00:00

I want to set BCDEdit \set increaseuserva 3072 in my c++ desktop application.
I try to use system() function to set, but it's not work.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,448 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,562 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,425 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Castorix31 82,116 Reputation points
    2022-09-27T15:52:45.387+00:00

    This works for me (x86 on Windows 10 21H1) :

                        BOOL bWow64 = false;  
                        IsWow64Process(GetCurrentProcess(), &bWow64);  
                        if (bWow64)  
                        {  
                            PVOID OldValue = NULL;  
                            if (Wow64DisableWow64FsRedirection(&OldValue))  
                            {  
                                //...  
                            }  
                        }  
                        ShellExecute(0, L"runas", L"BCDEdit.exe", L"/set increaseuserva 3072", NULL, SW_SHOWNORMAL);
    
    3 people found this answer helpful.

  2. RLWA32 41,031 Reputation points
    2022-09-27T08:39:26.073+00:00

    BCDEdit requires administrator privileges. So your application must be running "as Administrator".

    Before doing this I suggest you carefully read https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit--set#memory-related-settings and also 4-gigabyte-tuning. Do you have a very good reason for changing this setting? Make sure you have a good system backup available.

    2 people found this answer helpful.

  3. Limitless Technology 44,001 Reputation points
    2022-09-30T07:45:27.893+00:00

    Hi,

    Thank you for your question and reaching out.

    I understand that you're having issues running the bcedit command in your desktop. Have you tried running manually opening Command Prompt in administrative mode? To do so, here are the commands:

    c:\WINDOWS\system32>bcdedit /set safeboot network
    c:\WINDOWS\system32>shutdown -r -f -t 0

    Then try running the BCEDIT command again.

    -------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments