0x90
0x90

Reputation: 41002

How to call system() in an opened administrator program and gives it the same privileges?

I am writing a c++ application in Windows that runs as administrator. However, while calling the system() command, it seems that the command doesn't have admin privileges (can't create file in the C:\Program Files (x86)\ directory).

How can I avoid using CreateProcess ?

Upvotes: 4

Views: 7259

Answers (1)

Serdalis
Serdalis

Reputation: 10489

If you use system you can use:

system("runas /user:<admin-user> \"program.exe\"");

Or ShellExecute:

ShellExecute(hwnd, "runas", "program.exe", 0, 0, SW_SHOWNORMAL);

This Stackoverflow Question
details the CreateProcess method pretty well.

Upvotes: 5

Related Questions