I want to write a program to shut down windows in N seconds. The easiest method I know to shutdown windows is to call system() with
shutdown -s -t XXXX
where XXXX is the given time. However system() only accepts string as a parameter. How can I call system("shutdown -s -t 7200") where 7200 is inputed by the user?
I’d use
InitiateSystemShutdowninstead. You could useExitWindowsorExitWindowsEx, but neither of those directly supports the delay being asked about in the original question, so you’d have to add code to do that delaying (e.g., usingSetTimer). That’s certainly possible, but incurs extra work without accomplishing anything extra in return.If you insist on using
system, you can usesprintf(or something similar) to create the string you pass tosystem: