source: nscp/include/firewall_helpers.hpp @ c391984

0.4.00.4.10.4.2
Last change on this file since c391984 was a0e17ff, checked in by Michael Medin <michael@…>, 4 years ago

Added a lot of missing files and cleanup source folder a bit for the 0.3.7 release

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <netfw.h>
2
3
4#pragma once
5
6
7namespace installer {
8        class firewall_exception {
9        private:
10                std::wstring error_;
11        public:
12                firewall_exception(std::wstring error) : error_(error) {}
13                firewall_exception(std::wstring error, DWORD code) : error_(error) {
14                        // TODO format error
15                }
16
17        };
18        class firewall {
19        public:
20                INetFwMgr* aquire_firewall_mgr() {
21                        HRESULT hr = S_OK;
22                        INetFwMgr* fwMgr = NULL;
23
24                        // Create an instance of the firewall settings manager.
25                        hr = CoCreateInstance(__uuidof(NetFwMgr), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void**)&fwMgr );
26                        if (FAILED(hr)) {
27                                throw
28                                printf("CoCreateInstance failed: 0x%08lx\n", hr);
29                                goto error;
30                        }
31
32                        // Retrieve the local firewall policy.
33                        hr = fwMgr->get_LocalPolicy(&fwPolicy);
34                        if (FAILED(hr))
35                        {
36                                printf("get_LocalPolicy failed: 0x%08lx\n", hr);
37                                goto error;
38                        }
39
40                        // Retrieve the firewall profile currently in effect.
41                        hr = fwPolicy->get_CurrentProfile(fwProfile);
42                        if (FAILED(hr))
43                        {
44                                printf("get_CurrentProfile failed: 0x%08lx\n", hr);
45                                goto error;
46                        }
47
48error:
49
50                        // Release the local firewall policy.
51                        if (fwPolicy != NULL)
52                        {
53                                fwPolicy->Release();
54                        }
55
56                        // Release the firewall settings manager.
57                        if (fwMgr != NULL)
58                        {
59                                fwMgr->Release();
60                        }
61
62                        return hr;
63                }
64
65
66        };
67
68}
Note: See TracBrowser for help on using the repository browser.