sachintha81 17 Junior Poster in Training

I'm using the following code (which I found on the net) to register an exe as a Windows Firewall Exception using C# code.


Type type = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication");
INetFwAuthorizedApplication authorizedApp = Activator.CreateInstance(type) as INetFwAuthorizedApplication;

// Set properties of authorizedApp here.

Type objectType = Type.GetTypeFromCLSID(new Guid("{304CE942-6E39-40D8-943A-B913C40C9CD4}"));
INetFwMgr firewallMgr = Activator.CreateInstance(objectType) as INetFwMgr;
firewallMgr.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(authorizedApp);


This code works fine and gets my job done, thought I don't fully understand the code. However, my problem is, can I obtain this CLSID of Firewall Manager Class, namely "{304CE942-6E39-40D8-943A-B913C40C9CD4}", programmatically, without hard coding it like here? Is this information stored somewhere in the OS or the .NET framework? It has to be there right?

I also happen to notice that this ID is has a registry entry in the registry in the following location.

HKEY_CLASSES_ROOT/CLSID/{304CE942-6E39-40D8-943A-B913C40C9CD4}

However, the problem is the key itself is the registry entry name so it is kind of no use to me here. What I need is a dynamic way of obtaining this key. Anybody has got any idea?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.