Guest WB Posted August 26, 2008 Posted August 26, 2008 Is there any way to determine if a service has started via a batch file? I tried using "sc" but it doesn't return any errorlevel. Thanks -- Bill Baker
Guest Pegasus \(MVP\) Posted August 26, 2008 Posted August 26, 2008 Re: Determine if a service has started via batch file "WB" <WB@discussions.microsoft.com> wrote in message news:E9711A82-E9D3-4663-90D2-EB649586B060@microsoft.com... > Is there any way to determine if a service has started via a batch file? I > tried using "sc" but it doesn't return any errorlevel. > > Thanks > -- > Bill Baker Your question is a little ambiguous. - Do you want to know if a service has been started automatically or by a batch file command? I don't think you can find out - it makes no difference how you start the service. - Do you want to use a batch file in order to determine the status of a batch file? That's easy - the command net start | find /i "NameOfService" will tell you.
Guest WB Posted August 26, 2008 Posted August 26, 2008 Re: Determine if a service has started via batch file Thanks for the quick reply. net start {service} sets errorlevel=2, so this will work fine. Thanks again, -- Bill Baker "Pegasus (MVP)" wrote: > > "WB" <WB@discussions.microsoft.com> wrote in message > news:E9711A82-E9D3-4663-90D2-EB649586B060@microsoft.com... > > Is there any way to determine if a service has started via a batch file? I > > tried using "sc" but it doesn't return any errorlevel. > > > > Thanks > > -- > > Bill Baker > > Your question is a little ambiguous. > - Do you want to know if a service has been started automatically > or by a batch file command? I don't think you can find out - it > makes no difference how you start the service. > - Do you want to use a batch file in order to determine the status > of a batch file? That's easy - the command > net start | find /i "NameOfService" > will tell you. > > >
Guest Pegasus \(MVP\) Posted August 26, 2008 Posted August 26, 2008 Re: Determine if a service has started via batch file That's not quite what you asked. Your original question was: How to determine if a service has started. The command net start {ServiceName} will actually start the service if it can (which is beyond the scope of your question). Still, if you don't mind starting an inactive service then your solution will do nicely. "WB" <WB@discussions.microsoft.com> wrote in message news:CD7B20FE-84EB-40AD-ACC6-698D2B138F76@microsoft.com... > Thanks for the quick reply. net start {service} sets errorlevel=2, so this > will work fine. > > Thanks again, > -- > Bill Baker > > > "Pegasus (MVP)" wrote: > >> >> "WB" <WB@discussions.microsoft.com> wrote in message >> news:E9711A82-E9D3-4663-90D2-EB649586B060@microsoft.com... >> > Is there any way to determine if a service has started via a batch >> > file? I >> > tried using "sc" but it doesn't return any errorlevel. >> > >> > Thanks >> > -- >> > Bill Baker >> >> Your question is a little ambiguous. >> - Do you want to know if a service has been started automatically >> or by a batch file command? I don't think you can find out - it >> makes no difference how you start the service. >> - Do you want to use a batch file in order to determine the status >> of a batch file? That's easy - the command >> net start | find /i "NameOfService" >> will tell you. >> >> >>
Guest Bill Grant Posted August 26, 2008 Posted August 26, 2008 Re: Determine if a service has started via batch file If you do "sc start " you should get an "already running" message if it has already started. "WB" <WB@discussions.microsoft.com> wrote in message news:E9711A82-E9D3-4663-90D2-EB649586B060@microsoft.com... > Is there any way to determine if a service has started via a batch file? I > tried using "sc" but it doesn't return any errorlevel. > > Thanks > -- > Bill Baker
Guest harrykrishna.nospam@online.ie Posted August 29, 2008 Posted August 29, 2008 Re: Determine if a service has started via batch file You could include a find statement with SC and then the errorlevel will show 0 if found or 1 if not. Something like: SC QUERY SPOOLER | FIND /I "RUNNING" IF ERRORLEVEL 1 ECHO NOT RUNNING ETC ETC Hope this helps.... WB <WB@discussions.microsoft.com> wrote: >Is there any way to determine if a service has started via a batch file? I >tried using "sc" but it doesn't return any errorlevel. > >Thanks
Recommended Posts