This (untested) should work on Windows 2000 or better (requires ADSI).
Is vbscript - run under Windows Scripting Host ie csript scriptname
'Test to see if a service is running
Dim strComputer
Dim strService
Dim strUser
Dim strPassword
Dim oComputer
On Error Resume Next
strComputer = "computername"
Set oComputer = Getobject("WinNT://" & strComputer & ",Computer")
Set oService = oComputer.Getobject("MSSQLServer","Service")
'so = oService
If (Err.Number <> 0) Then
Wscript.Echo(Err.Description&" "&Err.Number)
Wscript.Quit
End If
Select Case so.Status
Case ADS_SERVICE_STOPPED
MsgBox "Microsoft SQL Service has stopped.", vbOKOnly, "Check Service"
Case ADS_SERVICE_RUNNING
MsgBox "Microsoft SQL Service is running.", vbOKOnly, "Check Service"
Case ADS_SERVICE_PAUSED
MsgBox "Microsoft SQL Service has paused.", vbOKOnly, "Check Service"
Case ADS_SERVICE_ERROR
MsgBox "Microsoft SQL Service has errors.", vbOKOnly, "Check Service"
End Select
''''Clean Up''''
Set strComputer = Nothing
Set strService = Nothing
Set strUser = Nothing
Set strPassword = Nothing
This Technet link refers and shows how to incorporate an automatic restart.
http://support.microsoft.com/default.aspx?scid=kb;en-us;247557
> -----Original Message-----
> From: [Email Address Removed] [SMTP:[Email Address Removed] Sent: Friday, February 28, 2003 12:55 PM
> To: LazyDBA.com Discussion
> Subject: Re: Db down Alert
>
>
>
> If your database is clustered, Microsoft Cluster Server does a "select
> @@servername" every 5 seconds to check to make sure the SQL Server is
> running. You could probably mimic that with a scheduled task in NT to get
> the same type of effect - even if your server is not clustered. The user
> account you use would just need public access (grant then as a login to
> SQL Server but not as a user to any databases).
>
> Thanks,
> Lisa Greetham
> Database Administrator, Corporate Internet Group
> Bank One
>
>
>
>
> "Shibu MB" <[Email Address Removed] 02/28/2003 01:41 AM
>
> To
> "LazyDBA.com Discussion" <[Email Address Removed] cc
>
> Subject
> Db down Alert
>
>
>
>
>
>
> Hi all ...
>
> Can anyone suggest me or share the script which checks if the db
> (
> sqlserver 2000) is up or not and if it goes down or throws an error alert
> the DBA???
>
> Thanks
> Shibu
>
>
> DISCLAIMER:
> This message (including attachment if any) is confidential and may be
> privileged. Before opening attachments please check them for viruses and
> defects. MindTree Consulting Private Limited (MindTree) will not be
> responsible for any viruses or defects or any forwarded attachments
> emanating either from within MindTree or outside. If you have received
> this message by mistake please notify the sender by return e-mail and
> delete this message from your system. Any unauthorized use or
> dissemination of this message in whole or in part is strictly prohibited.
> Please note that e-mails are susceptible to change and MindTree shall not
> be liable for any improper, untimely or incomplete transmission.
>
>
>
>
> This transmission may contain information that is privileged, confidential
> and/or exempt from disclosure under applicable law. If you are not the
> intended recipient, you are hereby notified that any disclosure, copying,
> distribution, or use of the information contained herein (including any
> reliance thereon) is STRICTLY PROHIBITED. If you received this
> transmission in error, please immediately contact the sender and destroy
> the material in its entirety, whether in electronic or hard copy format.
> Thank you.
>
>
> ---------------------------------------------------------------------
> TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
> To unsubscribe, e-mail: mssqldba-[Email Address Removed] For additional commands, e-mail: mssqldba-[Email Address Removed]MS Sql Server LazyDBA home page