I want to know how the system()
function can give me more privilege to execute a program under system32, but the CreateProcessA()
function doesn't?
The code I tested:
int main()
{
STARTUPINFOA si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(STARTUPINFOA));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(si);
std::string path = "C:\\Windows\\System32\\ComputerDefaults.exe";
system(("start " + path).c_str());
if (CreateProcessA(path.c_str(), NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi) != 0)
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}
std::cout << "CreateProcessA() Failed. Error code #" << GetLastError() << "\n";
return 0;
}
CreateProcessA() Failed. Error code #740
Error lookup value 740:
The requested operation requires elevation.
When the system()
function executes the ComputerDefaults.exe
, it is running successfully.
Why is it happening?