hi
I want to run sfc.exe command in c++.
I use this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
Run Command with user permission
*/
HINSTANCE SFCSevenRun() {
return ShellExecute(NULL, "runas", "C:\\WINDOWS\\system32\\cmd.exe",
"/k C:\\WINDOWS\\system32\\sfc.exe /scannow", 0, SW_SHOWNORMAL);
}
/*
Run Command without user permission
*/
HINSTANCE SFCXpRun() {
return ShellExecute(NULL, "open", "C:\\WINDOWS\\system32\\cmd.exe",
"/k C:\\WINDOWS\\system32\\sfc.exe /scannow", 0, SW_SHOWNORMAL);
}
If I run cmd in usual mode (use open instead of runas ) I get this message: "You must be an administrator running a console session in order to use the sfc utility."
In xp it is OK, but in windows 7 I receive this message in cmd when I run as admin: "windows resource protection could not start the repair service"
I create a batch file with these commands
I have that problem as the above.
But When I run this batch file directly by right click and choose "run as admin" or run cmd.exe as admin and write my batch file address in cmd.exe console everything is OK. Please Help me. How can I fix this problem?
I found the answer myself:
I created a project that compiled by 32bit compiler but my windows7 platform was 64bit and this did not work.
After that, I test this project in windows7 32bit and was OK. and I created project with 64bit compiler in windows7 64bit and that was OK too.