Instead of using the command shell to see if the SQL Agent Service is running. You could use the following command.
EXEC master..xp_servicecontrol QueryState, SQLServerAgent
Thanks for the tip. But the stored procedure you pointed is undocumented. I am trying to use only documented procs to be able to use it between SQL Server versions. Even Microsoft very seldom changing undocumented stored procs it may happened. Check a good tip about undocumented stored procedures in the last SQL Server Magazine and changes that are done with some of them in sp4.