Security Question

Log on Script to restart Windows 7 Firewall not working

03/24/2014 3159 views

I am trying to create a VBS log on script that will restart Windows 7 Firewall for Administrators and users. I am having some difficulties because the script doesn't seem to work for both cases. I am knew to VBS any help would be appreciated, thanks.

Dim regValue
set WshShell = CreateObject( "WScript.Shell" )
strServiceName = "MpsSvc"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'") regValue = WshShell.RegRead( "HKLM\SYSTEM\CurrentControlSet\Services\MpsSvc\Start" ) If regValue = 3 Or regValue = 2  Or regValue = 0  Then
 'Stop Service
 For Each objService in colListOfServices
 'Start Service
 For Each objService in colListOfServices
End If set WshShell = nothing
Set objWMIService = nothing
Set colListOfServices = nothing WScript.Quit
Answer Summary:
1 Comment   [ + ] Show comment


  • Can you define "works for both cases" please?
    • Both cases means that it will work for admininstrators and users without privileges. Hope that answers your question.

All Answers


Well that breaks away from the norm a bit, your dont normally let standard users disable the firewall. Anyway guess you have a need. Your script above will do the job, but normal users dont have access to stop/start the firewall.

You need to give them access via the methods below (no point in reinvenniting the wheel when someone else has already done it).

GPO is the best and easiest option

Using SC.exe to add the ACLs (you will need admin rights to do/deploy this)

Extra notes for SC.exe


Good luck with your can of worms!



Also, you need a

 WScript.Sleep 3000

After you stop the service as this action is not instant - you need to give it some time to stop before you can start it again.

Answered 03/25/2014 by: rileyz
Red Belt

  • Thanks, I will take a look at these website and see what I can do. Thanks again for the help.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ