ファイアウォール経由でアプリケーションを許可しようとしていますが、アクティブでパッシブモードでftpする必要があります。私のアプリケーションにファイアウォール経由でのアクセスを許可するC#
MyApp.Classes.INetFwMgr mgr = new MyApp.Classes.INetFwMgr();
mgr.AuthorizeApplication(Application.ProductName, Application.StartupPath,
NET_FW_SCOPE_.NET_FW_SCOPE_ALL,
NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY);
と仕事をしていませんクラス:コードの上に使用して
private const string CLSID_FIREWALL_MANAGER =
"{304CE942-6E39-40D8-943A-B913C40C9CD4}";
private static NetFwTypeLib.INetFwMgr GetFirewallManager()
{
Type objectType = Type.GetTypeFromCLSID(
new Guid(CLSID_FIREWALL_MANAGER));
return Activator.CreateInstance(objectType)
as NetFwTypeLib.INetFwMgr;
}
private const string PROGID_AUTHORIZED_APPLICATION =
"HNetCfg.FwAuthorizedApplication";
public bool AuthorizeApplication(string title, string applicationPath,
NET_FW_SCOPE_ scope, NET_FW_IP_VERSION_ ipVersion)
{
// Create the type from prog id
Type type = Type.GetTypeFromProgID(PROGID_AUTHORIZED_APPLICATION);
INetFwAuthorizedApplication auth = Activator.CreateInstance(type)
as INetFwAuthorizedApplication;
auth.Name = title;
auth.ProcessImageFileName = applicationPath; //Getting Access Denied Exception Here
auth.Scope = scope;
auth.IpVersion = ipVersion;
auth.Enabled = true;
NetFwTypeLib.INetFwMgr manager = GetFirewallManager();
try
{
manager.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(auth);
}
catch (Exception ex)
{
return false;
}
return true;
}
を、私はライン
上Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
C#の例外を取得ので、私はそれを使用してexexcute、罰金コンパイル以下のコードを試してみました
auth.ProcessImageFileName = applicationPath;
何をすべきか?
Edit1:
私はコードを使用してこれを管理者として実行しますか?
Edit2:
は、私はまた、実行コンテキストは、XPの勝利7、Vistaでは、することができPutting <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> in manifest did not make a difference
PSThisプログラムを試してみました
参考までに、「C#.net」などはありません。 –
このコードの実行コンテキストとは何ですか?通常のプログラムでは、ファイアウォールを強制的にオープンにするだけではなく、それによってファイアウォールを持つことができます。少なくとも管理者特権が必要になります。通常はインストーラでしか入手できない種類のものです。サーバーのシナリオでは、明らかにアクセス権を明示的に与えるためにLAN管理者に任せておきます。 –