5

I'm new here and I wanted to write a C++ source code that executes the command:

sfc.exe /scannow

But it doesn't work. Windows-resource protection can't start repair service.

I'm a student and I'm in my 10th grade and I do not have computer science at school, so I wanted to ask the question here.

Here is my code excerpt:

#include<stdlib.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    system("sfc.exe /scannow");
}

The compiler brings no errors. I am using the GNU/GCC compiler, Windows 10 1803 and Code::Blocks(IDE)

I hope you can understand it :)

lucki1000
  • 87
  • 1
  • 8

2 Answers2

1

Your code works, if you delete the # before main() and using namespace and just for completion I added return 0; at the end.

Code:

#include<stdlib.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    system("sfc.exe /scannow"); 
    return 0;
}

Run the code with administrator rights and everything should be okay.

xMutzelx
  • 566
  • 8
  • 22
  • No, it works not. error Windows resource protection could not start the repair service, but thanks – lucki1000 May 11 '18 at 11:15
  • @lucki1000 Mhm, I think you dont have a problem with your code then, you might have a problem within windows. Have your tried to fix this message? For example: [1]: https://www.drivereasy.com/knowledge/fixed-windows-resource-protection-could-not-start-the-repair-service-sfc-error/ – xMutzelx May 11 '18 at 11:18
  • I have already tried other things, but if I start the cmd as admin then I can command use successful – lucki1000 May 11 '18 at 11:25
1

If you are using 64 bit system but your compiler is 32 bit means you will get this error. If you are using visual studio c++ and your pc is 64 bit system means change the platform to 64 bit.

For more information, ref this answer https://stackoverflow.com/a/20872354/6599346

Vignesh VRT
  • 399
  • 3
  • 15