Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
741 views
in Technique[技术] by (71.8m points)

How to run a batch file in order to shutdown PC from C++ service on a Windows 10 machine?

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:estoto.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...