Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to stop and start services as a user on NT Server?

Status
Not open for further replies.

Molenski

IS-IT--Management
Jan 24, 2002
288
0
0
DE
Hi there,

I put a thread on the NT4 forum yesterday but I thought I'd try here.

We have an application running on our NT Servers which runs as a service. The problem with this is that the service hangs frequently which requires a server reboot (don't ask why, it's a long story!). The application is critical to our service and occasionally this means that the servers have to be cold rebooted which isn't good.

My boss has asked me to create a batch file which will attempt to stop and restart the service, this probably isn't going to work but I need to do it anyway.

I came up with a net stop/start option using Atonce.exe but a bog standard user with no rights has no permissions to run it. What I'd like is this sort of thing:

If service is hanging try to stop it. If you are able to stop it then restart it and send a message to the user letting them know that they can try and start the application and if not possibly the option to shutdown the server cleanly. I have no idea where to start on this and bear in mind that this would have to be run as a user with no rights. Also, the script would have to point at one particular server for as little user intervention as possible.

Can anyone help????

Thanks a lot.

Molenski
As my bessie bud Kev always says - Get involved!!!
 
I had the same problem with a program. Below is the script that I made. It shuts down the process waits 10 seconds and then restarts the process. When the process is back up a ready message box appears. It is used on XP pro so your permissions may need to be adjusted.

*********************************************************
Dim strMsg,WshShell, oExec, i, strComputer

Set WshShell = CreateObject("WScript.Shell")
Check = false
i = 0
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'YOUR PROCESS HERE'")
For Each objProcess in colProcessList
objProcess.Terminate()

Do
i = i + 1
If i = 1000000 Then
Check = True
End IF
Loop until Check = True

IF Check = True Then
Set oExec = WshShell.Exec("YOUR PROCESS HERE")
IF oExec.Status = 0 Then
MsgBox "Ready!",,"PROGRAM NAME HERE"
Else
MsgBox "Try Again!",,"PROGRAM NAME HERE"
End IF
End IF

Next
***********************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top