Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi I want to run sfc.exe command in c++.
I use this code:
C++
/*
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"

Please Help me. How can I fix this problem?
Posted

1 solution

I think you can right click your program, and select "run by administrator". Win7 has more effective authentication
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900