简体   繁体   中英

Netsh set rule depends on OS language

I was creating a batch script to run several commands to enable winrm, changing network category and such and I got across a problem with the netsh command, specifically netsh advfirewall firewall set rule group=”Network Discovery” new enable=yes

After digging around and messing with UAC and registry I understood my problem: Windows language.

So the command is setting the rule to the Network Discovery , however in my language (portuguese btw) the group is called Deteção de Rede and thus making the script unable to run across several Windows machines with different languages, making the user enable network sharing manually.

My question is: Is there global way of calling the Network Discovery group? or creating a new group linking to it?

This is my script btw:

@ECHO ON
REM Run as admin
powershell.exe /c Get-NetConnectionProfile;
powershell.exe /c Set-NetConnectionProfile -NetworkCategory Private;
powershell.exe /c netsh advfirewall firewall set rule group=”Deteção de Rede” new enable=yes
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}
cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}

@ECHO Done.

Thankfully to @lit I found a way to set the rules to the group. Used the command powershell.exe /c netsh advfirewall firewall set rule group="@FirewallAPI.dll,-32752" new enable=Yes to enable Network Sharing and powershell.exe /c netsh advfirewall firewall set rule group="@FirewallAPI.dll,-28502" new enable=Yes to enable files and print sharing (if you want to use this to target a windows machine you may want to activate them both) and now i'm able to run my ansible playbook to windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM