Failure calling netsh to add firewall exception
<p>Hi I tried to add Firewall exception for my exe in a machine through my go code</p>

<p>This is my code</p>

<pre><code>// Firewall.go
package main

import (
    "fmt"
    "os/exec"
)

func main() {
    cmdArgs := []string{"advfirewall", "firewall", "add","rule","name=\"Allow My Service\"","dir=in","action=allow","program=\"C:\\Program Files\\Product\\Product.exe\""}
    out,err:=exec.Command("netsh",cmdArgs...).Output()  
    if err !=nil{
    fmt.Println("err:::",err)
    }
    fmt.Println("Out::",string(out))
}
</code></pre>

<p>But i don't get what i need.</p>

<p>The Output which i get is</p>

<pre><code>err::: exit status 1
Out::
A specified value is not valid.

Usage: add rule name=&lt;string&gt;
      dir=in|out
      action=allow|block|bypass
      [program=&lt;program path&gt;]
      [service=&lt;service short name&gt;|any]
      [description=&lt;string&gt;]
      [enable=yes|no (default=yes)]
      [profile=public|private|domain|any[,...]]
      [localip=any|&lt;IPv4 address&gt;|&lt;IPv6 address&gt;|&lt;subnet&gt;|&lt;range&gt;|&lt;list&gt;]
      [remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|
         &lt;IPv4 address&gt;|&lt;IPv6 address&gt;|&lt;subnet&gt;|&lt;range&gt;|&lt;list&gt;]
      [localport=0-65535|&lt;port range&gt;[,...]|RPC|RPC-EPMap|IPHTTPS|any (default=
ny)]
      [remoteport=0-65535|&lt;port range&gt;[,...]|any (default=any)]
      [protocol=0-255|icmpv4|icmpv6|icmpv4:type,code|icmpv6:type,code|
         tcp|udp|any (default=any)]
      [interfacetype=wireless|lan|ras|any]
      [rmtcomputergrp=&lt;SDDL string&gt;]
      [rmtusrgrp=&lt;SDDL string&gt;]
      [edge=yes|deferapp|deferuser|no (default=no)]
      [security=authenticate|authenc|authdynenc|authnoencap|notrequired
         (default=notrequired)]

Remarks:

      - Add a new inbound or outbound rule to the firewall policy.
      - Rule name should be unique and cannot be "all".
      - If a remote computer or user group is specified, security must be
        authenticate, authenc, authdynenc, or authnoencap.
      - Setting security to authdynenc allows systems to dynamically
        negotiate the use of encryption for traffic that matches
        a given Windows Firewall rule. Encryption is negotiated based on
        existing connection security rule properties. This option
        enables the ability of a machine to accept the first TCP
        or UDP packet of an inbound IPsec connection as long as
        it is secured, but not encrypted, using IPsec.
        Once the first packet is processed, the server will
        re-negotiate the connection and upgrade it so that
        all subsequent communications are fully encrypted.
      - If action=bypass, the remote computer group must be specified when dir=
n.
      - If service=any, the rule applies only to services.
      - ICMP type or code can be "any".
      - Edge can only be specified for inbound rules.
      - AuthEnc and authnoencap cannot be used together.
      - Authdynenc is valid only when dir=in.
      - When authnoencap is set, the security=authenticate option becomes an
        optional parameter.

Examples:

      Add an inbound rule with no encapsulation security for messenger.exe:
      netsh advfirewall firewall add rule name="allow messenger"
      dir=in program="c:\programfiles\messenger\msmsgs.exe"
      security=authnoencap action=allow

      Add an outbound rule for port 80:
      netsh advfirewall firewall add rule name="allow80"
      protocol=TCP dir=out localport=80 action=block

      Add an inbound rule requiring security and encryption
      for TCP port 80 traffic:
      netsh advfirewall firewall add rule
      name="Require Encryption for Inbound TCP/80"
      protocol=TCP dir=in localport=80 security=authdynenc
      action=allow

      Add an inbound rule for messenger.exe and require security
      netsh advfirewall firewall add rule name="allow messenger"
      dir=in program="c:\program files\messenger\msmsgs.exe"
      security=authenticate action=allow

      Add an authenticated firewall bypass rule for group
      acmedomain\scanners identified by a SDDL string:
      netsh advfirewall firewall add rule name="allow scanners"
      dir=in rmtcomputergrp=&lt;SDDL string&gt; action=bypass
      security=authenticate

      Add an outbound allow rule for local ports 5000-5010 for udp-
      Add rule name="Allow port range" dir=out protocol=udp localport=5000-5010
action=allow 
</code></pre>

<p>Help me to resolve this issue. Thanks in Advance</p>