Reputation: 41002
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
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