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.
Please log in to comment



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.
Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja