.NET’s Imaginary quest to rule the world: Whitelisting ala managed style.
At some point, for some reason, maybe because of Episode III (or maybe not), you’re going to want to white list an application within the Windows XP SP2 Windows Firewall from managed code.
You can do this easily enough from VBScript by using this handy VBS snippet. If you want to do this from managed code you can use this blog entry as a resource. All you need is the code below and a reference to c:\windows\hnetcfg.dll.
using NetFwTypeLib;
[STAThread]
static void Main()
{
Type fw = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
object objFwMgr = Activator.CreateInstance(fw);
Type app = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication", false);
object objApp = Activator.CreateInstance(app);
((INetFwAuthorizedApplication)objApp).Name = ".NET Test WhiteListing";
((INetFwAuthorizedApplication)objApp).Scope = NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
((INetFwAuthorizedApplication)objApp).IpVersion = NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY;
((INetFwAuthorizedApplication)objApp).Enabled = true;
((INetFwAuthorizedApplication)objApp).ProcessImageFileName = @"C:\test.exe";
((INetFwMgr)objFwMgr).LocalPolicy.CurrentProfile.AuthorizedApplications.Add((INetFwAuthorizedApplication)objApp);
}
Let me know if you need a C# to VB.NET conversion.
Comments
- Anonymous
March 18, 2005
The comment has been removed - Anonymous
March 18, 2005
The comment has been removed - Anonymous
March 18, 2005
:) I won't disagree that this is a bad idea and yes you have to be admin to run the code successfully.
If you check the VBScript file you'll see that the recomendation is to run this type of code during installation of your app which under normal circumstances should be done by a sys admin.
HTH - Anonymous
March 18, 2005
Just an update...the VBScript URL from the original post is incorrect.
It should be: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ics/ics/inetfwauthorizedapplications_add.asp - Anonymous
May 17, 2005
The www.53dy.com is free movies web site , all movies is free !
Welcome to our web site !
http://www.53dy.com">http://www.53dy.com
免费电影 www.53dy.com 全部电影完全免费!
欢迎光临免费电影
http://www.53dy.com">http://www.53dy.com
The www.k58.org is free movies web site , all movies is free !
Welcome to our web site !
http://www.k58.org">http://www.k58.org
免费电影 www.k58.org 全部电影完全免费!
欢迎光临免费电影
http://www.k58.org">http://www.k58.org