6
次のように、私のアプリケーションをファイアウォールに追加するためにnetshを使用しました。ファイアウォールに追加する前に、アプリケーションがファイアウォールに追加されていないことを知る方法を教えてください。アプリケーションをファイアウォールに繰り返し追加したくないからです。アプリケーションがファイアウォールに追加されていないことを確認するにはどうすればよいですか?
ProcessStartInfo info = null;
try
{
using (Process proc = new Process())
{
string productAssembly = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)).LocalPath + "\\" + this.ProductName + ".exe";
string args = string.Format(CultureInfo.InvariantCulture, "advfirewall firewall add rule name=\"{0}\" dir=in action=allow program=\"{1}\" enable=yes", this.ProductName, productAssembly);
info = new ProcessStartInfo("netsh", args);
proc.StartInfo = info;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
この記事をチェックアウト:http://stackoverflow.com/questions/113755/programmatically-add-an-application-to-windows-firewall –
@TheGreatCOどちらも、それは追加およびこれについてです、別の質問ですについては、 –
を検出しています。通常、インストール中にこの操作を一度行います。この場合、ファイアウォールに追加するだけで、アンインストール時に削除するだけで確認する必要はありません。 –