I want to write a program to shut down windows in
N seconds. The easiest method I know to shutdown windows is to call
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?
InitiateSystemShutdown instead. You could use
ExitWindowsEx, 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., using
SetTimer). That's certainly possible, but incurs extra work without accomplishing anything extra in return.
If you insist on using
system, you can use
sprintf (or something similar) to create the string you pass to
char buffer; sprintf(buffer, "shutdown -s -t %d", seconds); system(buffer);
shutdownon the command line. Although it was edited in, I would recommend against ExitWindows(Ex) under the circumstances. To use them after a delay, you'd have to handle the delay part yourself -- extra work for no gain - Jerry Coffin 2012-04-03 20:25
systemisn't really the best way to do this. Simply call <code>InitiateSystemShutdown</code> - David Heffernan 2012-04-03 20:14