Only create firewall rule if it doesn't already exist.

This commit is contained in:
Josh Mudge 2019-11-20 15:31:40 -07:00
parent 96c047a98c
commit 0ea1bb0ba0
1 changed files with 2 additions and 2 deletions

View File

@ -44,8 +44,8 @@ func main() {
// Set server file path to 'file' // Set server file path to 'file'
var file = "-Program '" + dir + "\\server.exe'" var file = "-Program '" + dir + "\\server.exe'"
//Create firewall rule //Create firewall rule if no firewall rule exists.
cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow") cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "$r", "=", "Get-NetFirewallRule", "-DisplayName", "'Go Web Server'", "2>", "$null;", "if", "($r)", "{write-host 'found rule';}", "else", "{New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow}")
cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent. cmdinstance.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.
cmdinstance2 := exec.Command("cmd", "/C", "start", "http://localhost:8100") cmdinstance2 := exec.Command("cmd", "/C", "start", "http://localhost:8100")
cmdinstance2.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent. cmdinstance2.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.