P00n Posted May 18, 2011 Share Posted May 18, 2011 (edited) Hello - I currently have a couple of batch scripts which rely on a couple of utilities - I would like to see if AutoIt can solve my problems for me, and I am looking for some guidance. My "start" script is as follows: echo Starting <program name here>... net start "<servicename>" /yes start /wait "" "c:\Sleep.exe" 15 echo <program name here> started successfully Start "" "C:\<programnamehere>.exe" You can see I need a "pause" to ensure the service is running because executing the .exe file. I do not want ANY user input - no waiting for a keypress in either START or STOP - the messages I have there were for my own testing. My "STOP" script is as follows: echo Stopping <program name here> Start c:\pskill.exe "<program name here>.exe" net stop "<servicename>" /yes echo <program name here> stopped successfully You can see I need a "kill" script to hunt down the application window and kill it before stopping the service. Thanks for any help anyone can provide. Edited May 18, 2011 by P00n Link to comment Share on other sites More sharing options...
hannes08 Posted May 18, 2011 Share Posted May 18, 2011 Hello P00n, you can use Run() to run DOS commands or programs. There's a service UDF somewhere in the forum you can use to start and stop services pretty easily. Use a Sleep() command to pause a script. ProcessClose() will end a process. It's all there, just go ahead and start coding! Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
P00n Posted May 18, 2011 Author Share Posted May 18, 2011 (edited) Hello P00n, you can use Run() to run DOS commands or programs. There's a service UDF somewhere in the forum you can use to start and stop services pretty easily. Use a Sleep() command to pause a script. ProcessClose() will end a process. It's all there, just go ahead and start coding! Okay - thanks. Is there anything built in to AutoIt to do the net start/stop "service name" command or is this what I need another script for? Thanks! Edited May 18, 2011 by P00n Link to comment Share on other sites More sharing options...
hannes08 Posted May 18, 2011 Share Posted May 18, 2011 Hi p00n,you can do this in more than one way. Either use Run() to run your net stop/start or sc commands, or include the UDF from engine: With the second way you don't need to check external command calls. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
P00n Posted May 18, 2011 Author Share Posted May 18, 2011 Hi p00n, you can do this in more than one way. Either use Run() to run your net stop/start or sc commands, or include the UDF from engine: With the second way you don't need to check external command calls. Thanks for the help. In case anyone else finds this useful I figured out how to do it without any addition scripts: Start Script Run(@ComSpec & " /c " &"net start ""ApplicationName 9999.2"" /yes" ) Sleep(15000) Run("c:\<path to application>.exe") Notes: The @ComSpec /c allows you to run a command as a command line function. Please not the spaces before AND after the /c in quotes! Also - because my service name has spaces I had to double quote it - notice the "" Stop Script ProcessClose("<name of application>.exe") Run(@ComSpec & " /c " & "net stop ""ApplicationName 9999.2"" /yes" ) Notes: Same as above - be mindful of the spaces around /c and watch the "" The service that I start is VERY large - 300mb or so. I would "like" to have the script "know" when this service is "fully loaded" - is this possible even with the UDF link you sent? Link to comment Share on other sites More sharing options...
omikron48 Posted May 19, 2011 Share Posted May 19, 2011 You can use "sc query <servicename>" and process the output to determine whether a service is already running. I'm not sure whether "sc query" is better to use than "net start" or vice-versa. Link to comment Share on other sites More sharing options...
hannes08 Posted May 19, 2011 Share Posted May 19, 2011 You can use "sc query <servicename>" and process the output to determine whether a service is already running.I'm not sure whether "sc query" is better to use than "net start" or vice-versa.SC is better when you want to stop/start/query services on remote machines. Also sc can query the state of a service. But it won't give you an errorcode upon failure. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now