SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server Services


SQL Server Services

Author
Message
free_mascot
free_mascot
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7409 Visits: 2250
Good Day,

I am looking for small .bat code to find the status of SQL Server windows services.

In fact I have tried to find it on google but no luck Sad

Appreciate if anybody can help with this.

Thanks in advance.

Cheers!!!

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Adiga
Adiga
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6142 Visits: 21012
There is useful command line utility called "SC". With this you can query the service status as below.

SC query mssqlserver


Hope this helps.

Cheers,

Pradeep

Pradeep Adiga
Blog: sqldbadiaries.com
Twitter: @pradeepadiga
rlondon
rlondon
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1363 Visits: 1160
I have uploaded an attachment of a .vbs file (I changed the extension to .txt for uploading) that I put together to monitor windows services every few minutes and e-mail me with any changes. I would run this through a scheduled task and it worked great. The only problem was that if the server was restarted for any reason, the job would not run and I would have to start it manually. The script may be useful for you anyway. If anyone can figure out why it won't restart automatically let me know.
Attachments
MonitorServicesScript.txt (132 views, 1.00 KB)
free_mascot
free_mascot
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7409 Visits: 2250
Thank you Adiga & rlondon.

Yes both of your reply will be useful.

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34275 Visits: 16649
Here's a way of doing it in T-SQL. Obviously it won't work if the SQL Server service itself isn't running!

EXEC master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLAgent'



John
free_mascot
free_mascot
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7409 Visits: 2250
Thank you, John.

Your query works but in case if SQL server is down we won't be able to track it.

So any solutions are welcome; when SQL server stops Smile

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
2 Tim 3:16
2 Tim 3:16
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1837 Visits: 1547
You can create a scheduled job in another sql server on another box. Create a link and then run a simple query like "select count(*) from linkname..sys.sysdatabases;". You can schedule the job to run every minute and if the job fails, notify you by email.

Tim White
Jeffrey Williams 3188
Jeffrey Williams 3188
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18907 Visits: 10042
Using Powershell installed on any system that has network access:

PS> Get-WMIObject Win32_Service -computer {computer} | ? {$_.Name -like 'MSSQL*'} | Select Name, State

You can then extend this to send email what the state is not running, or you can issue a start, or anything else.

Jeffrey Williams
Problems are opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)SSC Guru (53K reputation)

Group: General Forum Members
Points: 53355 Visits: 17672
you could use VBS something along the lines of

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service where displayname like '%sql%'",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_Service instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "DisplayName: " & objItem.DisplayName
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "ProcessId: " & objItem.ProcessId
Wscript.Echo "Status: " & objItem.Status
Next

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
free_mascot
free_mascot
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7409 Visits: 2250
Hello '2 Tim 3:16',

Nice solution We can cerate the link server and surely it works but what if customer do not agree for link server?

Also due to some security issues some of the client do not allow linked server Smile

Thank you Jeffrey & Perry for your inputs.

Cheers!!!

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search