Here is a vbscript to do what you want to do
Turn on sharing and firewall
Option Explicit
Dim objShell
Dim fwMgr
Dim profile
Set objShell = CreateObject("Shell.Application")
If objShell.IsServiceRunning("SharedAccess") = False Then
'SharedAccess is not running so turn it on
objShell.ServiceStart "SharedAccess", True
wscript.sleep 1000
End If
Set fwMgr = CreateObject("HNetCfg.FwMgr")
Set profile = fwMgr.LocalPolicy.CurrentProfile
If profile.FirewallEnabled = False Then
'Firewall disabled so enable it
profile.FirewallEnabled = True
End If
Turn off sharing and firewall
Option Explicit
Dim objShell
Dim fwMgr
Dim profile
Set objShell = CreateObject("Shell.Application")
If objShell.IsServiceRunning("SharedAccess") = True Then
'SharedAccess is running so turn it off
objShell.ServiceStart "SharedAccess", False
wscript.sleep 1000
End If
Set fwMgr = CreateObject("HNetCfg.FwMgr")
Set profile = fwMgr.LocalPolicy.CurrentProfile
If profile.FirewallEnabled = True Then
'Firewall enabled so disable it
profile.FirewallEnabled = False
End If
Note that this works only when user is administrator
so if the user isn't an admin then you will have to utilize
RunAs functionality.