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

Basic Windows Hosting

# of Domains: 4
# of SQL Server Databases: 4
Disk Space: 50GB
Bandwidth: Unmetered
SQL Server 2016
Monthly: $4.99
More Information About Free Shared Windows Hosting Plan

Express Hyper-V Hosting

Dedicated Memory:2GB
Disk Space: 120GB
Bandwidth: Unmetered
Windows 2016/2012: Free
Monthly: $11.99
More Information About Express Windows Hyper-V Server

Dedicated Windows Server

CPU: Quad-Core X3440 CPU
RAM: 16GB RAM
Disk: 2x120GB SSD + 300GB SATA
RAID: RAID 1
Bandwidth: Unmetered
Windows 2016/2012: Free
Monthly: $79.00
More Information About Dedicated Windows Server with SSD
Kubernetes Hosting | Windows VPS Hosting | SQL Server Hosting | ASP.NET Hosting | Windows Hyper-V Hosting | Dedicated SQL Server Hosting | Dedicated Windows Hosting | DNN Hosting
Cloud Application Hosting | MongoDB Hosting | CockroachDB Hosting | MySQL Hosting | MariaDB Hosting | Wordpress Hosting | Magento Hosting | Drupal Hosting | PostgreSQL Hosting | OpenCart Hosting | Redis Hosting | SQL Server Cloud Hosting