Automatically restarting a Windows 2000 service 
Author Message
 Automatically restarting a Windows 2000 service

Hello,

I am relatively new to scripting so please go easy on me.  I apologize
if this is a stupid question, but I have looked around for an answer
to no avail.

I have an application that uses two Windows services.  The services
periodically fail for no apparent reason, so I need to be able to
automatically restart them daily.  I have tried several approaches,
but have been unsuccessful to this point.  Here is the script I am
using:

  Set Sh = CreateObject("WScript.Shell")

  svc1 = "first service"
  svc2 = "second service"

        Sh.Run "cmd /c net stop """ & scv1 & "",0,True
        WScript.Sleep 3000
        Sh.Run "cmd /c net stop """ & svc2 & "",0,True

        WScript.Sleep 10000

        Sh.Run "cmd /c net stop """ & scv1 & "",0,True
        WScript.Sleep 3000
        Sh.Run "cmd /c net stop """ & svc2 & "",0,True

I am attempting to stop the two services in succession, then pause for
a few seconds and restart them.  I have attempted to use the Windows
Scheduled Tasks application to schedule the script, but it does not
work.  The scheduled task appears to run, but the services are not
restarted.

When I launch the script from the command line, the second service
stops, but nothing else happens.

Is there a way to determine if my script is flawed?  Is there an
easier/more effective way to accomplish this task?

Thanks in advance for any help you can provide.

-Jeff Maxton



Tue, 15 Nov 2005 01:57:11 GMT  
 Automatically restarting a Windows 2000 service
I don't see anywhere in your script where a start command is issued....

It could be that scv1 won't stop unless scv2 has stopped (dependency) so
that is why you only see one service stopped.

Since you are using VBScript, you could bind to the service with

Dim s:     Set s = GetObject("WinNT://DOMAINNAME/servername/scv1,service")

    s.stop
wscript.sleep 10000
     s.start

You can also query with s.status to verify / ensure the services stop and
start.

Not criticizing, but there is definitley a better way to accomplish your
goal.  Start here

 http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b234001

Joe


Quote:
> Hello,

> I am relatively new to scripting so please go easy on me.  I apologize
> if this is a stupid question, but I have looked around for an answer
> to no avail.

> I have an application that uses two Windows services.  The services
> periodically fail for no apparent reason, so I need to be able to
> automatically restart them daily.  I have tried several approaches,
> but have been unsuccessful to this point.  Here is the script I am
> using:

>   Set Sh = CreateObject("WScript.Shell")

>   svc1 = "first service"
>   svc2 = "second service"

> Sh.Run "cmd /c net stop """ & scv1 & "",0,True
> WScript.Sleep 3000
> Sh.Run "cmd /c net stop """ & svc2 & "",0,True

> WScript.Sleep 10000

> Sh.Run "cmd /c net stop """ & scv1 & "",0,True
> WScript.Sleep 3000
> Sh.Run "cmd /c net stop """ & svc2 & "",0,True

> I am attempting to stop the two services in succession, then pause for
> a few seconds and restart them.  I have attempted to use the Windows
> Scheduled Tasks application to schedule the script, but it does not
> work.  The scheduled task appears to run, but the services are not
> restarted.

> When I launch the script from the command line, the second service
> stops, but nothing else happens.

> Is there a way to determine if my script is flawed?  Is there an
> easier/more effective way to accomplish this task?

> Thanks in advance for any help you can provide.

> -Jeff Maxton



Wed, 16 Nov 2005 02:40:18 GMT  
 Automatically restarting a Windows 2000 service

Quote:

> Not criticizing, but there is definitley a better way to accomplish your
> goal.  Start here

>  http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b234001

A couple of quick followup points on this technique -

+ it can be extremely fast, as well as being cleaner for local management.

+ To connect to the local system, you can use "." for the host system just
like in WMI:

Set ComputerObj = GetObject("WinNT://.")

--
Please respond in the newsgroup so everyone may benefit.
 http://dev.remotenetworktechnology.com
(email requests for support contract information welcomed)
 ----------
 Microsoft's new UNIFIED Terminal Services Newsgroup:



Wed, 16 Nov 2005 18:28:47 GMT  
 Automatically restarting a Windows 2000 service
Do you know a way to set recovery parameters for a service, what to do 1:st
time a service stops, 2:nd time and so on - basicly the properties found on
the recovery tab?

Regards
Dan-H?kan Davall



Quote:

> > Not criticizing, but there is definitley a better way to accomplish your
> > goal.  Start here

> >  http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b234001

> A couple of quick followup points on this technique -

> + it can be extremely fast, as well as being cleaner for local management.

> + To connect to the local system, you can use "." for the host system just
> like in WMI:

> Set ComputerObj = GetObject("WinNT://.")

> --
> Please respond in the newsgroup so everyone may benefit.
>  http://dev.remotenetworktechnology.com
> (email requests for support contract information welcomed)
>  ----------
>  Microsoft's new UNIFIED Terminal Services Newsgroup:




Fri, 09 Dec 2005 20:01:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. restart windows 2000 using vbscript

2. Windows 2000 Pro - Shutdown/Restart PC

3. Using WMI to obtain dependent services (restarting services and all dependent services)

4. Unable to send faxes using Windows 2000 Faxing service

5. FYI - Microsoft Windows 2000 Service Pack 1 now available

6. stop service in windows 2000/NT

7. Disabling a service in Windows 2000

8. Win 2000 Pro Restart - Again??

9. Novice Question: How to automatically add a BCC in Outlook 2000

10. automatically saving all messages in outlook 98/2000

11. Windows Script 5.5 Beta 1 setup for Windows 2000 available

12. writing vbscript to know the OS of a remote PC ( is WIndows NT or WIndows 2000)

 

 
Powered by phpBB® Forum Software