/build/static/layout/Breadcrumb_cap_w.png

Log on Script to restart Windows 7 Firewall not working

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
    objService.StopService()
 Next
 
 'Start Service
 For Each objService in colListOfServices
    objService.StartService()
 Next
 
End If set WshShell = nothing
Set objWMIService = nothing
Set colListOfServices = nothing WScript.Quit

1 Comment   [ + ] Show comment
  • Can you define "works for both cases" please? - rileyz 9 years ago
    • Both cases means that it will work for admininstrators and users without privileges. Hope that answers your question. - LostDisciple 9 years ago

Answers (1)

Answer Summary:
Posted by: rileyz 9 years ago
Red Belt
1

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
http://social.technet.microsoft.com/wiki/contents/articles/5752.how-to-grant-users-rights-to-manage-services-start-stop-etc.aspx 

Using SC.exe to add the ACLs (you will need admin rights to do/deploy this)
https://msmvps.com/blogs/erikr/archive/2007/09/26/set-permissions-on-a-specific-service-windows.aspx

Extra notes for SC.exe
http://serverfault.com/questions/187302/how-do-i-grant-start-stop-restart-permissions-on-a-service-to-an-arbitrary-user 

 

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.


Comments:
  • Thanks, I will take a look at these website and see what I can do. Thanks again for the help. - LostDisciple 9 years ago

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:

Share

 
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