问题
I have a C++ program that runs as a service on a 64-bit Windows 10 machine. In this program, I want to execute a batch file to remotely switch off Pcs. I tried to use the function system() as follows :
system("cmd.exe /C \"batchfile path"");
system("shutdown /s /f /t 15 /m IPAdress");
In the second case, nothing happens. And in the first case, when I put a shutdown in my batch file, nothing happens however when I put a line like :
echo Test >> D:\test\toto.txt
The line is well executed meaning that I can find the file toto.txt in the filepath indicated.
Finally I tried with the command ShellExecuteW() as follows but without any sucess (nothing happens):
ShellExecuteW(NULL, L"runas", L"cmd.exe", L"/S /C \" \"batchfile path"", NULL, 0);
Now I don't know what to do in order to shutdown remote Pcs from my C++ programm.
Can anyone help me please ?
Thanks in advance.
来源:https://stackoverflow.com/questions/65560755/how-to-run-a-batch-file-in-order-to-shutdown-pc-from-c-service-on-a-windows-10