Posts tagged ‘netsh’

Remote PC firewall on or off ?

I was asked; “how can I tell from a command line if the firewall is enabled on a PC on our network, using a command line?”

Netsh is a very powerful tool for querying and setting the status of most anything network related. There are both the ‘netsh firewall’ and ‘netsh advfirewall’ options depending if XP, or Vista and newer.  I will deal with the advanced firewall as it is commonly used with Vista and Win 7 these days. The following command will return the available options:

C:\>netsh advfirewall show

The following commands are available:

Commands in this context:
show allprofiles – Displays properties for all profiles.
show currentprofile – Displays properties for the active profile.
show domainprofile – Displays properties for the domain properties.
show global    – Displays the global properties.
show privateprofile – Displays properties for the private profile.
show publicprofile – Displays properties for the public profile.
show store     – Displays the policy store for the current interactive session.

As you are aware the Advanced firewall can be set differently for domain, home, or public networks.  We are concerned with how it is set now, while on our network so we will use the show currentprofile option.  The result returns numerous details. By piping the results to the find command we can limit the output and simply determine if the Windows firewall is on or off  ( note: /I ignores case of the text in quotes):

C:\>netsh advfirewall show currentprofile |find “State” /I
State                                 OFF

Chances are you will not want to run to the machine to check so you can make use of Sysinternals/Microsoft’s PSexec to run netsh, or any command, on a remote machine.  You will need to run this with admin privileges for the remote machine. Therefore it is generally done from the server using a domain admin account.

C:\PSTools>psexec \\PC1 netsh advfirewall show currentprofile |find “state” /I

PsExec v1.98 – Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals – http://www.sysinternals.com

Starting netsh on PC1…ice on PC1…
State                                 OFF
(the output will often end with the following when run remotely: netsh exited on PC1 with error code 0.)

PSexec can be downloaded for free from: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

Advertisement

Sage Simply Accounting (Sage 50) Firewall Rules

When installing Simply accounting (in this case specifically Simply 2011) it requires opening firewall ports on the server to allow clients to use the Connection Manager to access data . Simply provides the following information in its help files:

image

However for most installations you only require 4 rules. You can use the server’s “Windows Firewall with Advanced Security” console to manually create a each rule one by one by generating new rules, browsing to the related service (.exe), and set to “allow”, or you can use a command line and netsh to create the rules. Again a little tedious entering each lengthy command one at a time.

The easiest method is to use a simple batch file with the four commands included in the script below. To make the batch file a little more informative I have added a few lines with description, the ability to opt out, and to be able to verify each command completed successfully. However using just the 4 netsh lines is all you require. The netsh commands included are tailored to only allow access from the local subnet for added security.

Simply copy the lines below to notepad and save as a batch file using a name like AddRules.bat  There are a few related notes:

  • When saving use quotes around the name such as “AddRules.bat” in the Notepad ‘save as’ box, to ensure the .txt suffix will not be added to the name
  • Each netsh commands is one single line. It is wraps in the blog article.
  • When ready to run the batch file right click on it and choose “run as administrator (i.e. elevated privileges)

————————————————————————–

Echo Off
CLS
Echo  Batch file to configure Windows Firewall
Echo    for Sage Simply Accounting 2011 using
Echo      Windows Firewall with Advanced Security
Echo        [Access will be limited to local subnet]
Echo.
Echo click Ctrl+C to escape
Pause
Echo on

netsh advfirewall firewall add rule name=”Simply Connection Manager” dir=in program=”C:\Program Files (x86)\Winsim\ConnectionManager\SimplyConnectionManager.exe” remoteip=localsubnet action=allow

netsh advfirewall firewall add rule name=”Simply Tray Icon” dir=in program=”C:\Program Files (x86)\Winsim\ConnectionManager\Simply.SystemTrayIcon.exe” remoteip=localsubnet action=allow

netsh advfirewall firewall add rule name=”Simply MySQL” dir=in program=”C:\Program Files (x86)\Winsim\ConnectionManager\MySqlBinary\5.0.38\mysql\mysqld-nt.exe” remoteip=localsubnet action=allow

netsh advfirewall firewall add rule name=”Simply MySQL Admin” dir=in program=”C:\Program Files (x86)\Winsim\ConnectionManager\MySqlBinary\5.0.38\mysql\mysqladmin.exe” remoteip=localsubnet action=allow

Echo off
Echo  “ok” should have been displayed after each rule was applied
Echo     Refresh Windows Firewall with Advanced Security to view added rules
Pause
Exit

Update/Note:  I have noticed when cutting and pasting from this article the quotation marks become unrecognized characters on most systems.  Simply paste the abov text in notepad and use Find & Replace to replace all with standard keyboard quotation characters.

Tag Cloud