Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Script to automatically restart service after system start

Reply
Thread Tools Display Modes

Script to automatically restart service after system start

 
 
Markus Wetzel
Guest
Posts: n/a

 
      01-18-2010
Hi,

after booting my w2k3 server I have to restart a service (OpenVPN) in
order to have it working correctly. I don't know if this is an issue
with the OpenVPN config but for now I would like to have a script that
automatically restarts the OpenVPN service ~5 minutes after the system
startup.

I wrote a little batch file (c:\temp\openvpnrestart.bat) with sleep and
net stop/start commands and created a new scheduled task that should
start while starting the system (with user "Administrator"). But it
seems that the script does not work properly while beeing started by a
scheduled task. Starting it manually works perfectly.

How am I able to automatically restart a service ~5 minutes after system
and service startup?

Kind regards,
Markus
 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      01-18-2010


"Markus Wetzel" <> said this in news item
news:hj1i32$fbi$...
> Hi,
>
> after booting my w2k3 server I have to restart a service (OpenVPN) in
> order to have it working correctly. I don't know if this is an issue with
> the OpenVPN config but for now I would like to have a script that
> automatically restarts the OpenVPN service ~5 minutes after the system
> startup.
>
> I wrote a little batch file (c:\temp\openvpnrestart.bat) with sleep and
> net stop/start commands and created a new scheduled task that should start
> while starting the system (with user "Administrator"). But it seems that
> the script does not work properly while beeing started by a scheduled
> task. Starting it manually works perfectly.
>
> How am I able to automatically restart a service ~5 minutes after system
> and service startup?
>
> Kind regards,
> Markus


Let's have a look at your script!

 
Reply With Quote
 
Markus Wetzel
Guest
Posts: n/a

 
      01-18-2010
Am 18.01.2010 13:47, schrieb Pegasus [MVP]:
>
> Let's have a look at your script!


No problem:

@echo off
sleep 300
echo "OpenVPN Service beenden"
net stop "OpenVPN Service"
sleep 10
echo "OpenVPN Service starten"
net start "OpenVPN Service"

I have to correct myself: The script is in the directory C:\Programme
(German windows) and is called "OpenVPN restart.bat"

It works great when I start it by clicking on it. (For testing purposes
with sleep 5. Could the sleep 300 command be a problem? Maybe script
timeout or something like that?)





 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      01-18-2010


"Markus Wetzel" <> said this in news item
news:hj2135$9bj$...
> Am 18.01.2010 13:47, schrieb Pegasus [MVP]:
>>
>> Let's have a look at your script!

>
> No problem:
>
> @echo off
> sleep 300
> echo "OpenVPN Service beenden"
> net stop "OpenVPN Service"
> sleep 10
> echo "OpenVPN Service starten"
> net start "OpenVPN Service"
>
> I have to correct myself: The script is in the directory C:\Programme
> (German windows) and is called "OpenVPN restart.bat"
>
> It works great when I start it by clicking on it. (For testing purposes
> with sleep 5. Could the sleep 300 command be a problem? Maybe script
> timeout or something like that?)


When you want your batch files to be robust then you must fully qualify all
executables that are not native to Windows. Sleep.exe is not native to
Windows and it could be stored anywhere on your disk. You can actually
replace it with ping.exe, which is a native Windows program. You should also
add some diagnostics to your batch file so that you can see what's going on.
Try this version:

@echo off
echo Batchdatei gestartet am %date% um %time:~0, 5% >> c:\test.txt
ping localhost -n 300 > nul
echo "OpenVPN Service beenden" >> c:\test.txt
net stop "OpenVPN Service" 1>> c:\test.txt 2>>&1
echo 10 Sekunden warten >> c:\test.txt
ping localhost -n 10 > nul
echo "OpenVPN Service starten" >> c:\test.txt
net start "OpenVPN Service" 1>> c:\test.txt 2>>&1
echo Batchdatei beendet um %time:~0, 5% >> c:\test.txt
echo\ >> c:\test.txt

If the batch file still fails to run then you can examine the full runtime
details in c:\test.txt.


 
Reply With Quote
 
Markus Wetzel
Guest
Posts: n/a

 
      01-18-2010
Am 18.01.2010 17:38, schrieb Pegasus [MVP]:
> Try this version:
>


Thank you, I will give it a try and report back to you if it still does
not work.

 
Reply With Quote
 
Markus Wetzel
Guest
Posts: n/a

 
      01-19-2010
I booted the machine several times but after each restart the OpenVPN
service is not working correctly until I do a manual restart of the
service. According to the logfile the batch file worss properly but it
seems that it has no real effect on the OpenVPN issue. So I still have
to do a manual restart of the service.

So there has to be another problem but sadly this will have nothing to
do with m.p.w.server.scripting
 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      01-19-2010


"Markus Wetzel" <> said this in news item
news:hj322g$2ik$...
> I booted the machine several times but after each restart the OpenVPN
> service is not working correctly until I do a manual restart of the
> service. According to the logfile the batch file worss properly but it
> seems that it has no real effect on the OpenVPN issue. So I still have to
> do a manual restart of the service.
>
> So there has to be another problem but sadly this will have nothing to do
> with m.p.w.server.scripting


Thanks for the feedback. I am not familiar with the OpenVPN service and I
therefore do not know what the issue is that you observe. Presumably it
allows you to set up a VPN with some other machine. Could it be that this
VPN is context-sensitive? Take, for example, the simple command

net use Q: \\Server\Share

When executed as part of the startup script then it will work perfectly
well, yet drive Q: will be invisible to the user who subsequently logs on.
Why? Because it was executed within the context of the startup environment
and NOT within the context of the user's logon session.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ActiveSync Won't Sync dherrstrom ActiveSync 8 01-15-2011 03:06 AM
active sync issue mk3100 patrick craig ActiveSync 0 01-15-2010 05:06 AM
Windows Update Error [Error number: 0x80245003] Marcus PC Tech Windows Update 20 12-24-2009 03:15 AM
Exchange Sync Issues Harry ActiveSync 0 08-24-2007 10:42 AM
NVIDIA GeForece 6800 and Vista w2m Windows Vista Hardware 19 06-11-2007 11:34 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59