From 0ea1bb0ba0f7ef010013a57b06cfd8c01dc6e095 Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Wed, 20 Nov 2019 15:31:40 -0700 Subject: [PATCH] Only create firewall rule if it doesn't already exist. --- All/setup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/All/setup.go b/All/setup.go index c4bd56e..a42a37d 100644 --- a/All/setup.go +++ b/All/setup.go @@ -44,8 +44,8 @@ func main() { // Set server file path to 'file' var file = "-Program '" + dir + "\\server.exe'" - //Create firewall rule - cmdinstance := exec.Command("powershell.exe", "-WindowStyle", "Hidden", "-Command", "New-NetFirewallRule", "-DisplayName", "'Go Web Server'", "-Direction", "Inbound", file, "-Action", "Allow") + //Create firewall rule if no firewall rule exists. + 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. cmdinstance2 := exec.Command("cmd", "/C", "start", "http://localhost:8100") cmdinstance2.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} // Make it silent.