Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Capture status of Windows service in a variable!

Author  Topic 

panthagani
Yak Posting Veteran

58 Posts

Posted - 2009-12-10 : 08:35:39
I would like to capture the status of WWW service (Started, Running, Stopped) in a sql variable and use the return value to send a mail to myself using SQL 2005 database mail.

Here is what I am attempting:

DECLARE @result int
EXEC @result = xp_cmdshell 'sc query w3svc |find "STATE"'
PRINT @result

Whether I use an int or a varchar for @result, it always returns 0.

Need ideas on how to capture the status of "sc query <service name>" in sql. Please advise!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-10 : 08:39:11

DECLARE @result table(data varchar(1000))
INSERT INTO @result
EXEC master..xp_cmdshell 'sc query w3svc |find "STATE"'
SELECT data FROM @result


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2009-12-10 : 08:44:12
Edit: Nevermind Madiv's was more useful :)



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-10 : 09:14:43
quote:
Originally posted by DP978

Edit: Nevermind Madiv's was more useful :)






No problem. If you have any solution post it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

panthagani
Yak Posting Veteran

58 Posts

Posted - 2009-12-15 : 11:18:28
I will try this out and post back. Thank you!
Go to Top of Page
   

- Advertisement -