How To Restart Windows DNS Service By VbScirpt?
Problem
Sometimes you need to re-start Windows DNS Service periodically in your Windows 2008/2003 server.
Solution
You can write a .vbs script file and schedule it as Windows task.
'Restart DNS
'-----------------------Stopping
DNS----------------------------
Wscript
.Echo
("Stopping
DNS........")
strComputer
= "."
Set objWMIService
= GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer
& "\root\cimv2")
Set colServiceList
= objWMIService
.ExecQuery
("Associators of " _
& "{Win32_Service.Name='DNS'}
Where " _
& "AssocClass=Win32_DependentService
" & "Role=Antecedent" )
For each objService
in colServiceList
objService
.StopService
()
Next
Wscript
.Sleep
20000
Set colServiceList
= objWMIService
.ExecQuery
_
("Select * from Win32_Service
where Name='DNS'")
For each objService
in colServiceList
errReturn
= objService
.StopService
()
Next
Wscript
.Echo
("DNS
Stopped")
Wscript
.Sleep
20000
'-----------------------Starting
DNS----------------------------
Wscript
.Echo
("Starting
DNS........")
strComputer
= "."
Set objWMIService
= GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer
& "\root\cimv2")
Set colServiceList
= objWMIService
.ExecQuery
_
("Select * from Win32_Service
where Name='DNS'")
For each objService
in colServiceList
errReturn
= objService
.StartService
()
Next
Wscript
.Sleep
20000
Set colServiceList
= objWMIService
.ExecQuery
("Associators of " _
& "{Win32_Service.Name='DNS'}
Where " _
& "AssocClass=Win32_DependentService
" & "Role=Dependent" )
For each objService
in colServiceList
objService
.StartService
()
Next
Wscript
.Echo
("DNS
Started")
Navigator
Other Knowledgebase Articles
Shared Hosting
# of Domains:
2
# of SQL Server Databases:
2
Disk Space:
Unlimited
Bandwidth:
Unlimited
Email:
Unlimited
SQL Server 2008 R2
Monthly:
$4.99
Windows Hyper-V Server
Dedicated Memory:
2GB
Disk Space:
200GB
Bandwidth:
Unlimited
Windows 2008/2003:
Free
Monthly:
$49.99
Dedicated Windows Server
CPU:
Intel Dual-Core Sandy Bridge I3-2100
RAM:
8GB RAM
Disk:
2x320GB SATA
RAID:
Host RAID 1
Bandwidth:
Unlimited
Windows 2008/2003:
Free
Monthly:
$99.00