Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
hi
I want to run sfc.exe command in c++.
I use this code:
/*
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 13-Oct-12 23:18pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 390
1 OriginalGriff 205
2 Zoltán Zörgő 124
3 Dave Kreskowiak 120
4 BillWoodruff 110
0 OriginalGriff 7,610
1 DamithSL 5,559
2 Sergey Alexandrovich Kryukov 5,324
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100