flemingmike Posted March 13, 2011 Share Posted March 13, 2011 Hello all. Is it possible to have a link that can start and stop a service on the web server? It is a windows 2003 server. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/ Share on other sites More sharing options...
.josh Posted March 13, 2011 Share Posted March 13, 2011 exec() will let you execute commands from command line from within script. Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186813 Share on other sites More sharing options...
flemingmike Posted March 13, 2011 Author Share Posted March 13, 2011 how would i properly write a shutdown restart with a time of 45 seconds exec ('c:\\WINDOWS\\system32\\shutdown.exe /r /t 45'); Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186859 Share on other sites More sharing options...
redarrow Posted March 13, 2011 Share Posted March 13, 2011 <?php /** * @author john * @copyright 2011 */ exec('shutdown -s -t ' . intval(30) . (30 ? ' -f' : '')); ?> try this. Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186882 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 That looks like a *NIX shutdown command. The OP is using WinD'ohs. Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186884 Share on other sites More sharing options...
redarrow Posted March 13, 2011 Share Posted March 13, 2011 I changed the code, it will work, just tried it my self lol. and it crashed all 10 servers was not funny. my fault. go off in 30 sec, i am using all the short hand exspressions -s example. For more information, see http://www.php.net/function.exec and http://www.ss64.com/nt/shutdown.html. Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186885 Share on other sites More sharing options...
flemingmike Posted March 13, 2011 Author Share Posted March 13, 2011 thanks guys. i just found this also: http://www.iis-aid.com/articles/trouble_shooting/warning_exec_function_exec_unable_to_fork if anyone is having issues with this, you need to give permissions. Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186886 Share on other sites More sharing options...
flemingmike Posted March 13, 2011 Author Share Posted March 13, 2011 shit. when i was testing with a batch file in the root of c that just changed directories, it was working. now i am trying exec('c:\WINDOWS\system32\cmd.exe /c START D:\Scripts\rh.bat'); here is rh.bat cd\ net stop "FireDaemon Service: Helium7" net start "FireDaemon Service: Helium7" exit Any ideas why this may not work? Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186887 Share on other sites More sharing options...
redarrow Posted March 13, 2011 Share Posted March 13, 2011 The exec() commands you learn as you go along , there millons off examples on google. Were here to teach you things wrong with your code , but not to write your code and teach you online like a school or collage. go here. http://www.php.net http://www.w3schools.com/php/default.asp http://www.tizag.com/phpT/ my code. <?php /** * @author john * @copyright 2011 */ if(isset($_POST['submit'])){ exec('shutdown -s -t ' . intval($_POST['shut']) . ($_POST['shut'] ? ' -f' : '')); } ?> <center> <form method="POST" action=" "> <b>WHEN SHOULD I SHUT DOWN MY PC!</b> <select name="shut"> <?php for($i=1; $i<10; $i++){ echo"<option value='$i'>$i<option>"; } ?> </select> <input type="submit" name="submit" value="Shut me down when!"> </center> I had the inpression, you wanted a code to turn you pc off , not to teach you php like a online school. www.amazon.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/230475-can-i-start-and-stop-services/#findComment-1186892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.