Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ run error with command sfc /scannow

Tags:

c++

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 :)

like image 238
lucki1000 Avatar asked Oct 29 '22 12:10

lucki1000


2 Answers

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

like image 135
Vignesh VRT Avatar answered Nov 15 '22 06:11

Vignesh VRT


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.

like image 26
xMutzelx Avatar answered Nov 15 '22 07:11

xMutzelx