diff --git a/HMSInfo.sln b/HMSInfo.sln new file mode 100644 index 0000000..2f3fc8d --- /dev/null +++ b/HMSInfo.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HMSInfo", "HMSInfo\HMSInfo.vcxproj", "{8B442DB4-D5A2-4751-B441-79C5720A0CEE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Debug|x64.ActiveCfg = Debug|x64 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Debug|x64.Build.0 = Debug|x64 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Debug|x86.ActiveCfg = Debug|Win32 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Debug|x86.Build.0 = Debug|Win32 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Release|x64.ActiveCfg = Release|x64 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Release|x64.Build.0 = Release|x64 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Release|x86.ActiveCfg = Release|Win32 + {8B442DB4-D5A2-4751-B441-79C5720A0CEE}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/HMSInfo/CredentialsFrm.cpp b/HMSInfo/CredentialsFrm.cpp new file mode 100644 index 0000000..426d1bc --- /dev/null +++ b/HMSInfo/CredentialsFrm.cpp @@ -0,0 +1,46 @@ +#include "stdafx.h" +#include "HMSInfo.h" +#include "CredentialsFrm.h" +#include "afxdialogex.h" + + +IMPLEMENT_DYNAMIC(CredentialsFrm, CDialogEx) + +CredentialsFrm::CredentialsFrm(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_CredentialsFrm, pParent) +{ +} + +CredentialsFrm::~CredentialsFrm() +{ +} + +void CredentialsFrm::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + SetDlgItemText(IDC_ed_username, L"Administrator"); + DDX_Control(pDX, IDC_ed_username, ed_username); + DDX_Control(pDX, IDC_ed_password, ed_password); + + HWND hWnd; + GetDlgItem(IDC_ed_password, &hWnd); + ::PostMessage(hWnd, WM_SETFOCUS, 0, 0); + +} + +BEGIN_MESSAGE_MAP(CredentialsFrm, CDialogEx) + ON_COMMAND(IDOK, OnOK) + ON_BN_CLICKED(IDOK, &CredentialsFrm::OnBnClickedOk) +END_MESSAGE_MAP() + +void CredentialsFrm::OnOK() +{ + this->ed_username.GetWindowTextW(hUsr); + this->ed_password.GetWindowTextW(hPwd); + CDialogEx::OnOK(); +} + +void CredentialsFrm::OnBnClickedOk() +{ + CDialogEx::OnOK(); +} diff --git a/HMSInfo/CredentialsFrm.h b/HMSInfo/CredentialsFrm.h new file mode 100644 index 0000000..02e280d --- /dev/null +++ b/HMSInfo/CredentialsFrm.h @@ -0,0 +1,33 @@ +#pragma once +#include "afxwin.h" + + +// CredentialsFrm dialog + +class CredentialsFrm : public CDialogEx +{ + DECLARE_DYNAMIC(CredentialsFrm) + +public: + CredentialsFrm(CWnd* pParent = nullptr); // standard constructor + virtual ~CredentialsFrm(); + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_CredentialsFrm }; +#endif + +protected: + void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support + + DECLARE_MESSAGE_MAP() +public: + CEdit ed_username; + CEdit ed_password; + CString hPwd; + CString hUsr; + //afx_msg void bt_scan(); + //afx_msg void OnEnChangeedusername(); + void OnOK() override; + afx_msg void OnBnClickedOk(); +}; diff --git a/HMSInfo/HMSInfo.cpp b/HMSInfo/HMSInfo.cpp new file mode 100644 index 0000000..a9abee3 --- /dev/null +++ b/HMSInfo/HMSInfo.cpp @@ -0,0 +1,108 @@ + +// HMSInfo.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include "HMSInfo.h" +#include "HMSInfoDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// CMainApp + +BEGIN_MESSAGE_MAP(CMainApp, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// CMainApp construction + +CMainApp::CMainApp() +{ + // support Restart Manager + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; + + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + + +// The one and only CMainApp object + +CMainApp theApp; + + +// CMainApp initialization + +BOOL CMainApp::InitInstance() +{ + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll Version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + if (!AfxSocketInit()) + { + AfxMessageBox(IDP_SOCKETS_INIT_FAILED); + return FALSE; + } + + + AfxEnableControlContainer(); + + // Create the shell manager, in case the dialog contains + // any shell tree view or shell list view controls. + CShellManager *pShellManager = new CShellManager; + + // Activate "Windows Native" visual manager for enabling themes in MFC controls + CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); + + // Standard initialization + // If you are not using these features and wish to reduce the size + // of your final executable, you should remove from the following + // the specific initialization routines you do not need + // Change the registry key under which our settings are stored + // TODO: You should modify this string to be something appropriate + // such as the name of your company or organization + SetRegistryKey(_T("Local AppWizard-Generated Applications")); + + CHMSInfoDlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + else if (nResponse == -1) + { + TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n"); + TRACE(traceAppMsg, 0, "Warning: if you are using MFC controls on the dialog, you cannot #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.\n"); + } + + // Delete the shell manager created above. + if (pShellManager != NULL) + { + delete pShellManager; + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} + diff --git a/HMSInfo/HMSInfo.h b/HMSInfo/HMSInfo.h new file mode 100644 index 0000000..bc4fd4a --- /dev/null +++ b/HMSInfo/HMSInfo.h @@ -0,0 +1,32 @@ + +// HMSInfo.h : main header file for the PROJECT_NAME application +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "include 'stdafx.h' before including this file for PCH" +#endif + +#include "resource.h" // main symbols + + +// CMainApp: +// See HMSInfo.cpp for the implementation of this class +// + +class CMainApp : public CWinApp +{ +public: + CMainApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + +// Implementation + + DECLARE_MESSAGE_MAP() +}; + +extern CMainApp theApp; \ No newline at end of file diff --git a/HMSInfo/HMSInfo.rc b/HMSInfo/HMSInfo.rc new file mode 100644 index 0000000..5666af2 Binary files /dev/null and b/HMSInfo/HMSInfo.rc differ diff --git a/HMSInfo/HMSInfo.vcxproj b/HMSInfo/HMSInfo.vcxproj new file mode 100644 index 0000000..34e1dda --- /dev/null +++ b/HMSInfo/HMSInfo.vcxproj @@ -0,0 +1,257 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {8B442DB4-D5A2-4751-B441-79C5720A0CEE} + HMSInfo + 8.1 + MFCProj + + + + Application + true + v140_xp + Unicode + Static + + + Application + false + v140_xp + true + Unicode + Static + + + Application + true + v140_xp + Unicode + Static + + + Application + false + v140_xp + true + Unicode + Static + + + + + + + + + + + + + + + + + + + + + true + C:\Users\Dravion\Documents\Visual Studio 2013\Projects\hms\5.6.7\hmailserver\hmailserver\source\Server\hMailServer;$(IncludePath) + + + true + C:\Users\Dravion\Documents\Visual Studio 2013\Projects\hms\5.6.7\hmailserver\hmailserver\source\Server\hMailServer;$(IncludePath) + + + false + ../codesigning/codesign.key + C:\Users\Dravion\Documents\Visual Studio 2013\Projects\hms\5.6.7\hmailserver\hmailserver\source\Server\hMailServer;$(IncludePath) + + + false + C:\Users\Dravion\Documents\Visual Studio 2013\Projects\hms\5.6.7\hmailserver\hmailserver\source\Server\hMailServer;$(IncludePath) + + + + Use + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + MultiThreaded + Async + + + Windows + notelemetry.obj /NODEFAULTLIB:LIBCMT %(AdditionalOptions) + ole32.lib;Iphlpapi.lib;%(AdditionalDependencies) + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + true + Async + + + Windows + notelemetry.obj %(AdditionalOptions) + ole32.lib;Iphlpapi.lib;%(AdditionalDependencies) + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + Full + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + StreamingSIMDExtensions2 + + + Windows + true + true + notelemetry.obj %(AdditionalOptions) + true + ../codesigning/codesign.pfx + NoErrorReport + true + false + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + Full + true + true + _CRT_SECURE_NO_WARNINGS;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + true + Async + + + Windows + true + true + ole32.lib;Iphlpapi.lib;%(AdditionalDependencies) + notelemetry.obj %(AdditionalOptions) + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HMSInfo/HMSInfo.vcxproj.filters b/HMSInfo/HMSInfo.vcxproj.filters new file mode 100644 index 0000000..40bfcfd --- /dev/null +++ b/HMSInfo/HMSInfo.vcxproj.filters @@ -0,0 +1,105 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Quelldateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + Headerdateien + + + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + Quelldateien + + + + + Ressourcendateien + + + + + Ressourcendateien + + + Headerdateien + + + + + Ressourcendateien + + + Ressourcendateien + + + Ressourcendateien + + + Ressourcendateien + + + \ No newline at end of file diff --git a/HMSInfo/HMSInfo.vcxproj.user b/HMSInfo/HMSInfo.vcxproj.user new file mode 100644 index 0000000..13066be --- /dev/null +++ b/HMSInfo/HMSInfo.vcxproj.user @@ -0,0 +1,6 @@ + + + + HMSInfo.rc + + \ No newline at end of file diff --git a/HMSInfo/HMSInfoDlg.cpp b/HMSInfo/HMSInfoDlg.cpp new file mode 100644 index 0000000..2473a40 --- /dev/null +++ b/HMSInfo/HMSInfoDlg.cpp @@ -0,0 +1,736 @@ +#include "stdafx.h" +#include "HMSInfo.h" +#include "HMSInfoDlg.h" +#include "afxdialogex.h" +#include +#include +#include +#include +#include "versioninfo.h" +#include "sysutils.h" +#include +#include +#include "ipenum.h" +#include "hMailServerInfo.h" +#include "CredentialsFrm.h" +#include + +using namespace std; + +// Globals +CString aIps; +CString hmsUsername = L"Administrator"; +CString hmsPassword = nullptr; + +// Firewall info forward declarations +HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2); + +// Get Firewall info +void CHMSInfoDlg::Get_FirewallSettings_PerProfileType(NET_FW_PROFILE_TYPE2 ProfileTypePassed, INetFwPolicy2* pNetFwPolicy2) +{ + VARIANT_BOOL bIsEnabled = FALSE; + NET_FW_ACTION action; + + if (SUCCEEDED(pNetFwPolicy2->get_FirewallEnabled(ProfileTypePassed, &bIsEnabled))) + { + CString fw; + fw.Format(L"%s %hs", L"Firewall is:", bIsEnabled?"Enabled":"Disabled"); + this->LIST_VAR_hMailServer.AddString(fw); + } + + if (SUCCEEDED(pNetFwPolicy2->get_BlockAllInboundTraffic(ProfileTypePassed, &bIsEnabled))) + { + CString fw; + fw.Format(L"%s %hs", L"Block all inbound traffic is:", bIsEnabled ? "Enabled" : "Disabled"); + this->LIST_VAR_hMailServer.AddString(fw); + } + + if (SUCCEEDED(pNetFwPolicy2->get_NotificationsDisabled(ProfileTypePassed, &bIsEnabled))) + { + CString fw; + fw.Format(L"%s %hs", L"Notifications are:", bIsEnabled ? "disabled" : "enabled"); + this->LIST_VAR_hMailServer.AddString(fw); + } + + if (SUCCEEDED(pNetFwPolicy2->get_UnicastResponsesToMulticastBroadcastDisabled(ProfileTypePassed, &bIsEnabled))) + { + CString fw; + fw.Format(L"%s %hs", L"UnicastResponsesToMulticastBroadcast is:", bIsEnabled ? "disabled" : "enabled"); + this->LIST_VAR_hMailServer.AddString(fw); + } + + if (SUCCEEDED(pNetFwPolicy2->get_DefaultInboundAction(ProfileTypePassed, &action))) + { + CString fw; + fw.Format(L"%s %hs", L"Default inbound action is:", action != NET_FW_ACTION_BLOCK ? "Allow" : "Block"); + this->LIST_VAR_hMailServer.AddString(fw); + } + + if (SUCCEEDED(pNetFwPolicy2->get_DefaultOutboundAction(ProfileTypePassed, &action))) + { + CString fw; + fw.Format(L"%s %hs", L"Default outbound action is:", action != NET_FW_ACTION_BLOCK ? "Allow" : "Block"); + this->LIST_VAR_hMailServer.AddString(fw); + } + +} + +// Instantiate INetFwPolicy2 +HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2) +{ + HRESULT hr; + + hr = CoCreateInstance( + __uuidof(NetFwPolicy2), + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(INetFwPolicy2), + (void**)ppNetFwPolicy2); + + if (FAILED(hr)) + { + printf("CoCreateInstance for INetFwPolicy2 failed: 0x%08lx\n", hr); + goto Cleanup; + } + +Cleanup: + + return hr; +} + +class CMyIPEnum : public CIPEnum +{ + BOOL EnumCallbackFunction(int nAdapter, const in_addr& address) override; +}; + +BOOL CMyIPEnum::EnumCallbackFunction(int nAdapter, const in_addr& address) +{ + CString ips = nullptr; + ips.Format(L"%d.%d.%d.%d", address.S_un.S_un_b.s_b1, + address.S_un.S_un_b.s_b2, address.S_un.S_un_b.s_b3, address.S_un.S_un_b.s_b4); + aIps = aIps + ips + L"\t/\t"; + + return TRUE; +} + +// CAboutDlg dialog used for App About +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg(); + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ABOUTBOX }; +#endif + + protected: + virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support + +// Implementation +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) +END_MESSAGE_MAP() + +CHMSInfoDlg::CHMSInfoDlg(CWnd* pParent /*=NULL*/) + : CDialogEx(IDD_HMSINFO_DIALOG, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); +} + +void CHMSInfoDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO_LIST, VAR_INFO_LIST); + DDX_Control(pDX, IDC_TAB1, MyTabCtrl); + DDX_Control(pDX, IDC_LIST_hMailServer, LIST_VAR_hMailServer); + +} + +BEGIN_MESSAGE_MAP(CHMSInfoDlg, CDialogEx) + ON_WM_SYSCOMMAND() + ON_WM_PAINT() + ON_BN_CLICKED(ID_BT_QUIT, &CHMSInfoDlg::OnBnClickedBtQuit) + ON_BN_CLICKED(IDC_BUTTON1, &CHMSInfoDlg::bt_scan) + ON_LBN_SELCHANGE(IDC_INFO_LIST, &CHMSInfoDlg::OnLbnSelchangeInfoList) + ON_BN_CLICKED(IDC_BT_SAVE, &CHMSInfoDlg::OnBnClickedBtSave) +ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CHMSInfoDlg::OnSelchangeTab1) +END_MESSAGE_MAP() + + +// CHMSInfoDlg message handlers +BOOL CHMSInfoDlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Add "Info" menu item to system menu. + ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); + ASSERT(IDM_ABOUTBOX < 0xF000); + + CMenu* pSysMenu = GetSystemMenu(FALSE); + if (pSysMenu != nullptr) + { + + CString strAboutMenu; + strAboutMenu.LoadString(IDS_ABOUTBOX); + + if (!strAboutMenu.IsEmpty()) + { + pSysMenu->AppendMenu(MF_SEPARATOR); + pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); + } + } + + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // Extra initialization + + MyTabCtrl.InsertItem(0, _T("General"), 1); + MyTabCtrl.InsertItem(1, _T("COM && Firewall"), 2); + + // Listbox, larger fonts + CFont m_font; + m_font.CreateFont(25, // Height + 2, // Width + 0, // Escapement + 0, // Orientation + FW_BLACK, // Weight + FALSE, // Italic + FALSE, // Underline + 0, // StrikeOut + DEFAULT_CHARSET, // CharSet + OUT_DEFAULT_PRECIS, // OutPrecision + CLIP_DEFAULT_PRECIS, // ClipPrecision + CLEARTYPE_QUALITY, // Quality + DEFAULT_PITCH | FF_SWISS, // PitchAndFamily + L"Arial"); // Facename + + VAR_INFO_LIST.SetFont(&m_font); + LIST_VAR_hMailServer.SetFont(&m_font); + + // Adjust size //width //height + VAR_INFO_LIST.SetWindowPos(nullptr,20,51,575, 461, 0); + + + + + + // Adjust size + this->LIST_VAR_hMailServer.SetWindowPos(nullptr, 20, 51, 575, 451, 0); + + this->LIST_VAR_hMailServer.AddString(L"No Data"); + + #ifdef _DEBUG + #ifdef _M_IX86 + this->SetWindowTextW(L"HMSinfo (Debug) - 32-Bit"); + #endif + + #ifdef _M_X64 + this->SetWindowTextW(L"HMSinfo (Debug) - 64-Bit"); + #endif + #else + #ifdef _M_IX86 + this->SetWindowTextW(L"HMSinfo (Release) - 32-Bit"); + #endif + + #ifdef _M_X64 + this->SetWindowTextW(L"HMSinfo (Release) - 64-Bit"); + #endif + #endif + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CHMSInfoDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialogEx::OnSysCommand(nID, lParam); + } +} + +void CHMSInfoDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else { + CDialogEx::OnPaint(); + } +} + +HCURSOR CHMSInfoDlg::OnQueryDragIcon() const +{ + return static_cast(m_hIcon); +} + +void CHMSInfoDlg::OnBnClickedBtQuit() +{ + CDialogEx::OnOK(); +} + +// Scan Button, collect all data +void CHMSInfoDlg::bt_scan() +{ + Sysutils *obj = new Sysutils(); + this->VAR_INFO_LIST.ResetContent(); + + // ##### Start WOW32 ##### + if (obj->IsHMS32_WOW64_Installed() == true) { + + CString varInstallDir = obj->GetHMS32WOW64InstallPath(); + CString releasedesc = obj->GetHMS32WOW64VersionInfo(); + + if (varInstallDir.GetLength() < 2) { + AfxMessageBox(L"No hMailServer found, finishing"); + AfxPostQuitMessage(0); + } + + VAR_INFO_LIST.AddString(L"Version: " + releasedesc +" (32-Bit on WOW64)"); + VAR_INFO_LIST.AddString(L"Installfolder: "+varInstallDir); + + CVersionInfo *verinfo + = new CVersionInfo(varInstallDir + "\\Bin\\libeay32.dll"); + CString v_fileversion = verinfo->GetFileversion(); + CString v_productversion = verinfo->GetProductVersion(); + int v_build = verinfo->GetBuildNumber(); + delete verinfo; + + CString msg; + msg.Format(L"%s %d", static_cast(v_fileversion), v_build); + VAR_INFO_LIST.AddString(L"OpenSSL Version: " + msg + " (click for details...)"); + + CString osbuild = nullptr; + osbuild.Format(L"Build: "+ obj->GetOSBuildEx()); + + CString bitreparse; + if (obj->GetOSArchitecture() == "32-bit") + bitreparse = L"32-Bit"; + + if (obj->GetOSArchitecture() == "64-bit") + bitreparse = L"64-Bit"; + + CString sp = nullptr; + + if (obj->GetOSServicePack() > 0) { + sp.Format(L"%d", obj->GetOSServicePack()); + VAR_INFO_LIST.AddString(L"OS: "+ obj->GetOSDesc() +" "+ osbuild +" "+ bitreparse +" SP "+ sp); + } + else { + VAR_INFO_LIST.AddString(L"OS: "+ obj->GetOSDesc() +" "+ osbuild +" "+ bitreparse +" RTM"); + } + + CString cpucores = nullptr; + cpucores.Format(L"%d", obj->GetCPUCores()); + + CString totalmemory = nullptr; + totalmemory.Format(L"%d", obj->GetTotalAvaiableMemory() / 1024); + + CString freememory = nullptr; + freememory.Format(L"%d", obj->GetFreeMemory() / 1024); + + CString maxorocessmemory = nullptr; + maxorocessmemory.Format(L"%d", obj->MaxProcessMemorySize() / 1024 / 1024); + + CString nicspeed = nullptr; + nicspeed.Format(L"%d %s", obj->GetNicSpeed() / 1000 / 1000,L" MBit/s"); + + CString nicenabled = nullptr; + nicenabled.Format(L"%s", static_cast(obj->GetNicIsEnabled())); + + VAR_INFO_LIST.AddString(L"CPU: " + obj->GetCPUInfo() +" "+ cpucores + " Cores"); + VAR_INFO_LIST.AddString(L"Total Memory avaiable: " + totalmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Free Memory avaiable: " + freememory + " MBytes ("+obj->GetMemoryInUse() +"% in use)"); + VAR_INFO_LIST.AddString(L"Granted hMailServer Memory: " + maxorocessmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Networkadapter: " + obj->GetNicInfo() +" "+nicspeed); + VAR_INFO_LIST.AddString(L"Networkadapter: " + nicenabled + " / Description: "+obj->GetNicConnectionID()); + VAR_INFO_LIST.AddString(L"Networkadapter-MAC-Address: " + obj->GetMacAddress()); + VAR_INFO_LIST.AddString(L"Default Gateway: " + obj->GetDefaultGateWay()); + + CMyIPEnum ip; + ip.Enumerate(); + + VAR_INFO_LIST.AddString(L"IP-Addresses: "+ aIps); + VAR_INFO_LIST.AddString(L"Virtualization: " + obj->GetIsVirtualBox()); + VAR_INFO_LIST.AddString(L"Database-" + obj->GetSQLDatabaseType(varInstallDir)); + + CString svc_status = nullptr; + svc_status.Format(L"hMailServer status: %hs", +obj->getServiceStatus()); + VAR_INFO_LIST.AddString(svc_status); + + CString svc_account = nullptr; + svc_account.Format(L"Service account: %s", +obj->GetServiceAccountName()); + VAR_INFO_LIST.AddString(svc_account); + + CString svc_startmode = nullptr; + svc_startmode.Format(L"Service Startmode: %s", +obj->GetServiceStartMode()); + VAR_INFO_LIST.AddString(svc_startmode); + VAR_INFO_LIST.AddString(L"Scan-Timestamp: " + obj->GetTimestamp()); + + } // ##### Stop WOW32 ##### + + // ##### Start Win32-Native ##### + if (obj->IsHMS32_native_installed() == true) { + + CString releasedesc = obj->GetHMS32NativeVersionInfo(); + CString vInstallDir = obj->GetHMS32InstallPath(); + + if (vInstallDir.GetLength() < 2) { + AfxMessageBox(L"No hMailServer found, finishing"); + AfxPostQuitMessage(0); + } + + VAR_INFO_LIST.AddString(L"Version: " + releasedesc + " (32-Bit, native)"); + VAR_INFO_LIST.AddString(L"Installfolder: " + vInstallDir); + + CString vInstallDate = obj->GetHMS32InstallDate(); + + vInstallDate.Insert(6, _T(".")); + vInstallDate.Insert(4, _T(".")); + _tprintf(L"1: %s\n", (LPCTSTR)vInstallDate); + + VAR_INFO_LIST.AddString(L"HMS-Installdate: " + vInstallDate); + + CVersionInfo *verinfo + = new CVersionInfo(vInstallDir + "\\Bin\\libeay32.dll"); + CString v_fileversion = verinfo->GetFileversion(); + CString v_productversion = verinfo->GetProductVersion(); + int v_build = verinfo->GetBuildNumber(); + delete verinfo; + + CString msg; + msg.Format(L"%s %d", static_cast(v_fileversion), v_build); + VAR_INFO_LIST.AddString(L"OpenSSL Version: " + msg + " (click for details...)"); + + CString cpucores = nullptr; + cpucores.Format(L"%d", obj->GetCPUCores()); + + CString totalmemory = nullptr; + totalmemory.Format(L"%d", obj->GetTotalAvaiableMemory() / 1024); + + CString freememory = nullptr; + freememory.Format(L"%d", obj->GetFreeMemory() / 1024); + + CString maxorocessmemory = nullptr; + maxorocessmemory.Format(L"%d", obj->MaxProcessMemorySize() / 1024 / 1024); + + CString nicspeed = nullptr; + nicspeed.Format(L"%d %s", obj->GetNicSpeed() / 1000 / 1000, L" MBit/s"); + + CString nicenabled = nullptr; + nicenabled.Format(L"%s", static_cast(obj->GetNicIsEnabled())); + + CString osbuild = nullptr; + osbuild.Format(L"Build %d", obj->GetOSBuild()); + + CString bitreparse; + if (obj->GetOSArchitecture() == "32-bit") + bitreparse = L"32-Bit"; + + if (obj->GetOSArchitecture() == "64-bit") + bitreparse = L"64-Bit"; + + CString sp = nullptr; + + if (obj->GetOSServicePack() > 0) { + sp.Format(L"%d", obj->GetOSServicePack()); + VAR_INFO_LIST.AddString(L"OS: " + obj->GetOSDesc() + " " + osbuild + " " + bitreparse + " SP " + sp); + } + else { + VAR_INFO_LIST.AddString(L"OS: " + obj->GetOSDesc() + " " + osbuild + " " + bitreparse + " RTM"); + } + + VAR_INFO_LIST.AddString(L"CPU: " + obj->GetCPUInfo() +cpucores+" Cores"); + VAR_INFO_LIST.AddString(L"Total RAM Memory installed: " + totalmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Free Memory avaiable: " + freememory + " MBytes (" + + obj->GetMemoryInUse() + "% in use)"); + VAR_INFO_LIST.AddString(L"Granted hMailServer Memory: " + maxorocessmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Ethernet: " + obj->GetNicInfo() + " " + nicspeed); + VAR_INFO_LIST.AddString(L"Ethernet: " + nicenabled); + VAR_INFO_LIST.AddString(L"Virtualization: " + obj->GetIsVirtualBox()); + VAR_INFO_LIST.AddString(L"Database-" + obj->GetSQLDatabaseType(vInstallDir)); + + } // ##### End Win32-Native ##### + + // ##### Start Win64-Native ##### + if (obj->IsHMS64_native_installed() == true) { + + CString releasedesc = obj->GetHMS32NativeVersionInfo(); + CString vInstallDir = obj->GetHMS32InstallPath(); + + if (vInstallDir.GetLength() < 2) { + AfxMessageBox(L"No hMailServer found, finishing"); + AfxPostQuitMessage(0); + } + + VAR_INFO_LIST.AddString(L"Version: " + releasedesc + " (32-Bit, native)"); + VAR_INFO_LIST.AddString(L"Installfolder: " + vInstallDir); + + CString vInstallDate = obj->GetHMS32InstallDate(); + + vInstallDate.Insert(6, _T(".")); + vInstallDate.Insert(4, _T(".")); + _tprintf(L"1: %s\n", (LPCTSTR)vInstallDate); + + VAR_INFO_LIST.AddString(L"HMS-Installdate: " + vInstallDate); + + CVersionInfo *verinfo + = new CVersionInfo(vInstallDir + "\\Bin\\libeay32.dll"); + CString v_fileversion = verinfo->GetFileversion(); + CString v_productversion = verinfo->GetProductVersion(); + int v_build = verinfo->GetBuildNumber(); + delete verinfo; + + CString msg; + msg.Format(L"%s %d", static_cast(v_fileversion), v_build); + VAR_INFO_LIST.AddString(L"OpenSSL Version: " + msg + " (click for details...)"); + + CString cpucores = nullptr; + cpucores.Format(L"%d", obj->GetCPUCores()); + + CString totalmemory = nullptr; + totalmemory.Format(L"%d", obj->GetTotalAvaiableMemory() / 1024); + + CString freememory = nullptr; + freememory.Format(L"%d", obj->GetFreeMemory() / 1024); + + CString maxorocessmemory = nullptr; + maxorocessmemory.Format(L"%d", obj->MaxProcessMemorySize() / 1024 / 1024); + + CString nicspeed = nullptr; + nicspeed.Format(L"%d %s", obj->GetNicSpeed() / 1000 / 1000, L" MBit/s"); + + CString nicenabled = nullptr; + nicenabled.Format(L"%s", static_cast(obj->GetNicIsEnabled())); + + CString osbuild = nullptr; + osbuild.Format(L"Build %d", obj->GetOSBuild()); + + CString bitreparse; + if (obj->GetOSArchitecture() == "32-bit") + bitreparse = L"32-Bit"; + + if (obj->GetOSArchitecture() == "64-bit") + bitreparse = L"64-Bit"; + + CString sp = nullptr; + + if (obj->GetOSServicePack() > 0) { + sp.Format(L"%d", obj->GetOSServicePack()); + VAR_INFO_LIST.AddString(L"OS: " + obj->GetOSDesc() + " " + osbuild + " " + bitreparse + " SP " + sp); + } + else { + VAR_INFO_LIST.AddString(L"OS: " + obj->GetOSDesc() + " " + osbuild + " " + bitreparse + " RTM"); + } + + VAR_INFO_LIST.AddString(L"CPU: " + obj->GetCPUInfo() + cpucores + " Cores"); + VAR_INFO_LIST.AddString(L"Total RAM Memory installed: " + totalmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Free Memory avaiable: " + freememory + " MBytes (" + + obj->GetMemoryInUse() + "% in use)"); + VAR_INFO_LIST.AddString(L"Granted hMailServer Memory: " + maxorocessmemory + " MBytes"); + VAR_INFO_LIST.AddString(L"Ethernet: " + obj->GetNicInfo() + " " + nicspeed); + VAR_INFO_LIST.AddString(L"Ethernet: " + nicenabled); + VAR_INFO_LIST.AddString(L"Virtualization: " + obj->GetIsVirtualBox()); + VAR_INFO_LIST.AddString(L"Database-" + obj->GetSQLDatabaseType(vInstallDir)); + + } + delete obj; +} // ##### End - Win64-Native ##### + +void CHMSInfoDlg::OnLbnSelchangeInfoList() { + + try { + CString strText; + + int index = this->VAR_INFO_LIST.GetCurSel(); + this->VAR_INFO_LIST.GetText(index, strText); + + int found = strText.Find(L"OpenSSL"); + if (found != -1) { + const int result = MessageBoxA(m_hWnd, "Review known OpenSSL vulnerabilities online? ", "Confirm", MB_ICONQUESTION | MB_YESNO | MB_SYSTEMMODAL); + + switch (result) { + case IDYES: + ShellExecute(nullptr, L"open", L"https://www.openssl.org/news/vulnerabilities.html", nullptr, nullptr, SW_SHOWNORMAL); + break; + case IDNO: + break; + default:; // do nothing; + } + } + } + catch (exception e) { + MessageBox(L"Not in list"); + } +} + +void CHMSInfoDlg::OnBnClickedBtSave() { + char strFilter[] = { "HMS Info Logfiles (*.log)|*.log|" }; + CFileDialog FileDlg(FALSE, CString(".log"), nullptr, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(strFilter)); + + if (FileDlg.DoModal() == IDOK) { + + CString vFile = FileDlg.GetFolderPath() +"\\"+ FileDlg.GetFileName(); + CString listitems; + + USES_CONVERSION; + + char const* fFilename = T2CA(vFile); + FILE *f = fopen(fFilename, "w"); + + if (f == nullptr) { + MessageBoxW(L"Error cannot create file!",L"Error",MB_ICONERROR); + exit(1); + } + + fprintf(f, "%S\n",L"### HMS-Info - Logfile ###"); + for (int i = 0; i < VAR_INFO_LIST.GetCount(); i++) { + int n = VAR_INFO_LIST.GetTextLen(i); + VAR_INFO_LIST.GetText(i, listitems.GetBuffer(n)); + listitems.ReleaseBuffer(); + fprintf(f, "%S\n", listitems.GetBuffer(0)); + } + fclose(f); + } +} + +// Event fired if tabs are selected and changed +void CHMSInfoDlg::OnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult) +{ + int iSel = MyTabCtrl.GetCurSel(); + + if (iSel == 0) + { + GetDlgItem(IDC_INFO_LIST)->ShowWindow(SW_SHOW); + GetDlgItem(IDC_LIST_hMailServer)->ShowWindow(SW_HIDE); + } + + else if (iSel == 1) + { + GetDlgItem(IDC_INFO_LIST)->ShowWindow(SW_HIDE); + + // Delete all the items + LIST_VAR_hMailServer.ResetContent(); + hMailServerInfo *obj = new hMailServerInfo(); + + if (hmsPassword.GetLength() == 0) { + CredentialsFrm dlg = new CredentialsFrm(); + + dlg.DoModal(); + hmsPassword = dlg.hPwd; + hmsUsername = dlg.hUsr; + } + + int result = obj->MaxDeliveryThreads(hmsUsername, hmsPassword); + int i_processedMessages = obj->ProcessedMessages(hmsUsername, hmsPassword); + CString i_startuptime = obj->StartTime(hmsUsername, hmsPassword); + CString dbconnections = obj->IsDBConnected(hmsUsername, hmsPassword); + int unCount = obj->getUndeliveredMessages(hmsUsername, hmsPassword); + + if (result != 0) { + + CString hVersion; + hVersion.Format(L"Build: "+ obj->Version()); + + LIST_VAR_hMailServer.AddString(hVersion); + + CString maxth; + maxth.Format(L"%d", result); + + CString i_mproc; + i_mproc.Format(L"%d", i_processedMessages); + + CString umCount; + umCount.Format(L"%d", unCount); + + LIST_VAR_hMailServer.AddString(L"MaxThreads: " + maxth); + LIST_VAR_hMailServer.AddString(L"ProcessedMessages: " + i_mproc); + LIST_VAR_hMailServer.AddString(L"Undelivered Messages: " + umCount); + LIST_VAR_hMailServer.AddString(L"Startuptime: " + i_startuptime); + LIST_VAR_hMailServer.AddString(L"DB-Connection: " + dbconnections); + + HRESULT hrComInit; + HRESULT hr; + + INetFwPolicy2 *pNetFwPolicy2 = nullptr; + + // Initialize COM. + hrComInit = CoInitializeEx( + nullptr, + COINIT_APARTMENTTHREADED + ); + + if (hrComInit != RPC_E_CHANGED_MODE) + { + if (FAILED(hrComInit)) + { + printf("CoInitializeEx failed: 0x%08lx\n", hrComInit); + goto Cleanup; + } + } + + // Retrieve INetFwPolicy2 + hr = WFCOMInitialize(&pNetFwPolicy2); + if (FAILED(hr)) + { + goto Cleanup; + } + + printf("Settings for the firewall public profile:\n"); + Get_FirewallSettings_PerProfileType(NET_FW_PROFILE2_PUBLIC, pNetFwPolicy2); + + Cleanup: + + // Release INetFwPolicy2 + if (pNetFwPolicy2 != nullptr) + { + pNetFwPolicy2->Release(); + } + + // Uninitialize COM. + if (SUCCEEDED(hrComInit)) + { + CoUninitialize(); + } + + } else { + LIST_VAR_hMailServer.AddString(L"Error: Username/Password wrong"); + } + } + + GetDlgItem(IDC_LIST_hMailServer)->ShowWindow(SW_SHOW); + + *pResult = 0; +} diff --git a/HMSInfo/HMSInfoDlg.h b/HMSInfo/HMSInfoDlg.h new file mode 100644 index 0000000..c5781f6 --- /dev/null +++ b/HMSInfo/HMSInfoDlg.h @@ -0,0 +1,45 @@ +#pragma once +#include "afxwin.h" +#include "afxcmn.h" +#include + +// CHMSInfoDlg dialog +class CHMSInfoDlg : public CDialogEx +{ +// Construction +public: + void Get_FirewallSettings_PerProfileType(NET_FW_PROFILE_TYPE2 ProfileTypePassed, INetFwPolicy2* pNetFwPolicy2); + CHMSInfoDlg(CWnd* pParent = nullptr); // standard constructor + +// Dialog Data +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_HMSINFO_DIALOG }; +#endif + + protected: + void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + BOOL OnInitDialog() override; + afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon() const; + DECLARE_MESSAGE_MAP() +public: + + afx_msg void OnBnClickedBtQuit(); + afx_msg void bt_scan(); + CListBox VAR_INFO_LIST; + afx_msg void OnLbnSelchangeInfoList(); + afx_msg void OnBnClickedBtSave(); + CTabCtrl tab_main; + CTabCtrl TabCtrlMain; + CTabCtrl MyTabCtrl; + afx_msg void OnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult); + CListBox LIST_VAR_hMailServer; + CStatic lb_status; +}; diff --git a/HMSInfo/ReadMe.txt b/HMSInfo/ReadMe.txt new file mode 100644 index 0000000..74839d8 --- /dev/null +++ b/HMSInfo/ReadMe.txt @@ -0,0 +1,12 @@ +Program: HMSInfo.exe +Version: 2.0.0.1 EN_US +Purpose: Dectects and inspects hMailServer Installations +Author: Dravion +Contact: dravion@ht-foss.net +Part of: HMS-Companion Pack 1.0.0.1 +License: AGPL +Neeeds Visual Studio 2017 to compile (Not the free Edition because of MFC-Support) +Encoding: UTF-8, Unicode - not Multibyte +Architectures: Win32 (32-Bit) and x64 (64-Bit) + + diff --git a/HMSInfo/Sysutils.cpp b/HMSInfo/Sysutils.cpp new file mode 100644 index 0000000..e76c5ce --- /dev/null +++ b/HMSInfo/Sysutils.cpp @@ -0,0 +1,2359 @@ +#include "stdafx.h" +#include "Sysutils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma comment(lib, "wbemuuid.lib") + +using namespace std; + +typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); + +LPFN_ISWOW64PROCESS fnIsWow64Process; + + +#define WORKING_BUFFER_SIZE 15000 +#define MAX_TRIES 3 + +#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) +#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) + +Sysutils::Sysutils(): gBitness(0) +{ +} + +CString Sysutils::GetHMS32WOW64VersionInfo() +{ + LPCWSTR pszValueName = L"DisplayName"; + HKEY hKey = nullptr; + + LPCTSTR pszSubkey = L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + // Buffer to store string read from registry + TCHAR szValue[1024] = { 0 }; + DWORD cbValueLength = sizeof(szValue); + + // Query string value + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + return CString(szValue); +} + +CString Sysutils::GetHMS64VersionInfo() +{ + LPCWSTR pszValueName = L"DisplayName"; + HKEY hKey = nullptr; + + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + // Buffer to store string read from registry + TCHAR szValue[1024] = { 0 }; + DWORD cbValueLength = sizeof(szValue); + + // Query string value + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + return CString(szValue); +} + +int Sysutils::GetTotalAvaiableMemory() +{ + HRESULT hres; + CString result; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) { } + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), + nullptr, + nullptr, + nullptr, + NULL, + nullptr, + nullptr, + &pSvc + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + // Set security flags + hres = CoSetProxyBlanket( + pSvc, + RPC_C_AUTHN_WINNT, + RPC_C_AUTHZ_NONE, + nullptr, + RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT * FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + // Get the data + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + + HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + if (SUCCEEDED(hr)) { + + VARIANT vtProp; + + // Get the value of the Name property + pclsObj->Get(L"TotalVisibleMemorySize", 0, &vtProp, nullptr, nullptr); + result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + // Cleanup + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + } + + int totalmemory = _wtoi(result); + return totalmemory; +} + +int Sysutils::GetFreeMemory() +{ + HRESULT hres; + CString result; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) { } + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), + nullptr, + nullptr, + nullptr, + NULL, + nullptr, + nullptr, + &pSvc + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + // Set security flags + hres = CoSetProxyBlanket( + pSvc, + RPC_C_AUTHN_WINNT, + RPC_C_AUTHZ_NONE, + nullptr, + RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT * FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + // Get the data from the query + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + if (SUCCEEDED(hr)) { + + VARIANT vtProp; + + // Get the value of the Name property + pclsObj->Get(L"FreePhysicalMemory", 0, &vtProp, nullptr, nullptr); + result = vtProp.bstrVal; + + VariantClear(&vtProp); + pclsObj->Release(); + + // Cleanup + // ======== + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + } + int totalmemory = _wtoi(result); + + return totalmemory; +} + +// Get OS Info +CString Sysutils::GetOSDesc() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) { } + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT * FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"Caption", 0, &vtProp, nullptr, nullptr); + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get CPU Infos +CString Sysutils::GetCPUInfo() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT name, numberofcores FROM Win32_Processor"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"Name", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get Ethernet NIC Info +CString Sysutils::GetNicInfo() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + // bstr_t("SELECT name FROM Win32_NetworkAdapter WHERE Manufacturer != 'Microsoft' "), + bstr_t("SELECT name FROM Win32_NetworkAdapter WHERE AdapterType ='Ethernet 802.3'"), + + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"Name", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get Ethernet NIC speed +int Sysutils::GetNicSpeed() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT speed FROM Win32_NetworkAdapter WHERE AdapterType ='Ethernet 802.3'"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"speed", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + int iSpeed = _wtoi(result); + + VariantClear(&vtProp); + pclsObj->Release(); + + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return iSpeed; +} + +// Get Ethernet NIC is enabled (true/false) +CString Sysutils::GetNicIsEnabled() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT netenabled FROM Win32_NetworkAdapter"), + //bstr_t("SELECT NetEnabled FROM Win32_NetworkAdapter"), + + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"netenabled", 0, &vtProp, nullptr, nullptr); + + CString result; + + if (vtProp.bstrVal == VARIANT_FALSE) { + result = "Enabled"; + } else { + result = "Disabled"; + } + + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get Ethernet Connection (customizeable description) +CString Sysutils::GetNicConnectionID() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT NetConnectionID FROM Win32_NetworkAdapter WHERE AdapterType ='Ethernet 802.3'"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"NetConnectionID", 0, &vtProp, nullptr, nullptr); + CString result = vtProp.bstrVal; + + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get DNS-Info +CString Sysutils::GetDNSInfo() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT name, numberofcores FROM Win32_Processor"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"Name", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get Mac-Address +CString Sysutils::GetMacAddress() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT MACAddress FROM Win32_NetworkAdapter WHERE AdapterType ='Ethernet 802.3'"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"MACAddress", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get Default Gateway +CString Sysutils::GetDefaultGateWay() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT Nexthop FROM Win32_IP4RouteTable WHERE (Mask='0.0.0.0')"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"Nexthop", 0, &vtProp, nullptr, nullptr); + + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Get DNSServers +CString Sysutils::GetDNSServers() +{ + + return (L"No Inpletemeted"); +} + + + +CString Sysutils::GetOSArchitecture() +{ + HRESULT hr; + CString result; + + hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hr)) { } + + hr = CoInitializeSecurity( + nullptr, + -1, // COM authentication + nullptr, // Authentication services + nullptr, // Reserved + RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication + RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation + nullptr, // Authentication info + EOAC_NONE, // Additional capabilities + nullptr // Reserved + ); + + if (FAILED(hr)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hr = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hr)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hr = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + NULL, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hr)) { + pLoc->Release(); + CoUninitialize(); + } + + // Set security flags + hr = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hr)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hr = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT OSArchitecture FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hr)){ + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + if (SUCCEEDED(hr)) { + VARIANT vtProp; + pclsObj->Get(L"OSArchitecture", 0, &vtProp, nullptr, nullptr); + result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + // Cleanup + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + } + result.MakeLower(); + return result; +} + +// Get Major Servicepack no. +int Sysutils::GetOSServicePack() +{ + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + GetVersionEx((OSVERSIONINFO*)&osvi); + GetSystemInfo(&si); + + return osvi.wServicePackMajor; +} + +// Get Major Servicepack no. +int Sysutils::GetOSBuild() +{ + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + GetVersionEx((OSVERSIONINFO*)&osvi); + GetSystemInfo(&si); + + return osvi.dwBuildNumber; +} + +CString Sysutils::GetOSBuildEx() +{ + HRESULT hr; + CString result; + + hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hr)) {} + + hr = CoInitializeSecurity( + nullptr, + -1, // COM authentication + nullptr, // Authentication services + nullptr, // Reserved + RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication + RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation + nullptr, // Authentication info + EOAC_NONE, // Additional capabilities + nullptr // Reserved + ); + + if (FAILED(hr)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hr = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hr)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hr = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + NULL, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hr)) { + pLoc->Release(); + CoUninitialize(); + } + + // Set security flags + hr = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hr)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hr = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT version FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hr)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + if (SUCCEEDED(hr)) { + VARIANT vtProp; + pclsObj->Get(L"version", 0, &vtProp, nullptr, nullptr); + result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + // Cleanup + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + } + result.MakeLower(); + return result; +} + +// Get CPU-Cores +int Sysutils::GetCPUCores() +{ + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + GetVersionEx((OSVERSIONINFO*)&osvi); + GetSystemInfo(&si); + + + return si.dwNumberOfProcessors; +} + +int Sysutils::MaxProcessMemorySize() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + + if (FAILED(hres)) { } + + IWbemLocator *pLoc = nullptr; + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), + nullptr, + nullptr, + nullptr, + NULL, + nullptr, + nullptr, + &pSvc + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + // Set security flags + hres = CoSetProxyBlanket( + pSvc, + RPC_C_AUTHN_WINNT, + RPC_C_AUTHZ_NONE, + nullptr, + RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT * FROM Win32_OperatingSystem"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"MaxProcessMemorySize", 0, &vtProp, nullptr, nullptr); + CString result = vtProp.bstrVal; + int maxprocmemory = _wtoi(result); + + VariantClear(&vtProp); + pclsObj->Release(); + + // Cleanup + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + + return maxprocmemory; +} + +CString Sysutils::GetTimestamp() +{ + time_t now = time(nullptr); + char buf[80]; + struct tm tstruct = *localtime(&now); + strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct); + + return (CString) buf; +} + +CString Sysutils::GetMemoryInUse() +{ + MEMORYSTATUSEX statex; + + statex.dwLength = sizeof(statex); + GlobalMemoryStatusEx(&statex); + + CString memoryfree = nullptr; + memoryfree.Format(L"%d", statex.dwMemoryLoad); + + return memoryfree; +} + + + +int Sysutils::GetHMSBitness() +{ + return this->gBitness; +} + +CString Sysutils::GetBinaryBitness(LPCTSTR lpApplicationName) +{ + DWORD dwBinaryType; + CString strResult = nullptr; + + if (GetBinaryType(lpApplicationName, &dwBinaryType) + && dwBinaryType == SCS_64BIT_BINARY) { + strResult = L"64-Bit (x64)"; + this->gBitness = 64; + } + + if (GetBinaryType(lpApplicationName, &dwBinaryType) + && dwBinaryType == SCS_32BIT_BINARY) { + strResult = L"32-Bit (x86)"; + gBitness = 32; + } + return strResult; +} + + +int Sysutils::GetMyBitness() +{ + DWORD dwBinaryType; + int bitness = 0; + + if (GetBinaryType(GetHMSInfoPath(), &dwBinaryType) + && dwBinaryType == SCS_64BIT_BINARY) { + bitness = 64; + } + + if (GetBinaryType(GetHMSInfoPath(), &dwBinaryType) + && dwBinaryType == SCS_32BIT_BINARY) { + bitness = 32; + } + return bitness; +} + +// Get WOW32 Installpath of hMailServer 32-Bit on Windows 64-Bit +CString Sysutils::GetHMS32WOW64InstallPath() +{ + LPCWSTR pszValueName = L"InstallLocation"; + LPCTSTR pszSubkey = L"SOFTWARE\\Wow6432Node\\hMailServer"; + HKEY hKey = nullptr; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + // Buffer to store string read from registry + TCHAR szValue[1024]; + DWORD cbValueLength = sizeof(szValue); + + // Query string value + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + return CString(szValue); + +} + +// Get Win64 Installpath of hMailServer 64-Bit, native +CString Sysutils::GetHMS64InstallPath() +{ + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + HKEY hKey = HKEY_LOCAL_MACHINE; + TCHAR szValue[1024] = { 0 }; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"InstallLocation"; + pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry HIVE Key"); + } + + // Buffer to store string + DWORD cbValueLength = sizeof(szValue); + + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry for HMS-Installinfo"); + } + } + return szValue; +} + +// Get Win32 Installpath of hMailServer 32-Bit, native +CString Sysutils::GetHMS32InstallPath() +{ + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + HKEY hKey = HKEY_LOCAL_MACHINE; + TCHAR szValue[1024] = { 0 }; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"InstallLocation"; + pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry HIVE Key"); + } + + // Buffer to store string + DWORD cbValueLength = sizeof(szValue); + + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry for HMS-Installinfo"); + } + } + return szValue; +} + +// Get Win32 Installdate of hMailServer 32-Bit, native +CString Sysutils::GetHMS32InstallDate() +{ + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + HKEY hKey = HKEY_LOCAL_MACHINE; + TCHAR szValue[1024]; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"InstallDate"; + pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry HIVE Key"); + } + + // Buffer to store string + DWORD cbValueLength = sizeof(szValue); + + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry for HMS-Installinfo"); + } + } + return szValue; +} + +CString Sysutils::GetHMS64NativeVersionInfo() +{ + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + HKEY hKey = HKEY_LOCAL_MACHINE; + TCHAR szValue[1024]; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"DisplayName"; + pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry HIVE Key"); + } + + // Buffer to store string + DWORD cbValueLength = sizeof(szValue); + + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry for HMS-Installinfo"); + } + } + return szValue; +} + +CString Sysutils::GetHMS32NativeVersionInfo() +{ + LPCTSTR pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + HKEY hKey = HKEY_LOCAL_MACHINE; + TCHAR szValue[1024]; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"DisplayName"; + pszSubkey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\hMailServer_is1"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry HIVE Key"); + } + + // Buffer to store string + DWORD cbValueLength = sizeof(szValue); + + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AfxMessageBox(L"Error on Querying Registry for HMS-Installinfo"); + } + } + return szValue; +} + +// Get the current path off HMSInfo.exe +CString Sysutils::GetHMSInfoPath() +{ + //char buf[1024] = { 0 }; + LPSTR buf = nullptr; + GetModuleFileNameA(nullptr, buf, sizeof(buf)); + char* wrkdir = (char*)buf; + return((CString)wrkdir); +} + +// Checking if we are running on a 32 or a 64-Bit Operating System +BOOL Sysutils::IsWow64() +{ + BOOL bIsWow64 = FALSE; + + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( + GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); + + if (nullptr != fnIsWow64Process) { + if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) { + //handle error - not yet. + } + } + return bIsWow64; +} + +bool Sysutils::IsNative64Bit() +{ + SYSTEM_INFO System; + GetNativeSystemInfo(&System); + bool result = false; + if (System.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) + { + result = true; + } + + return result; +} + +// check if a 32-Bit Version of hMailServer is allready on a 64-Bit OS installed. +bool Sysutils::IsHMS32_WOW64_Installed() { + + bool rst = false; + + if (this->GetOSArchitecture() == "64-bit") { + + LPCTSTR pszSubkey = L"SOFTWARE\\Wow6432Node\\hMailServer"; + HKEY hKey = HKEY_LOCAL_MACHINE; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"InstallLocation"; + pszSubkey = L"SOFTWARE\\Wow6432Node\\hMailServer"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + // Buffer to store string read from registry + TCHAR szValue[1024]; + DWORD cbValueLength = sizeof(szValue); + + // Query string value + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + CString wrkstr = szValue; + wrkstr = wrkstr +L"\\Bin\\hMailServer.exe"; + + if (this->GetBinaryBitness(wrkstr) == "32-Bit (x86)") + rst = true; + } + } + + return rst; +} + +bool Sysutils::IsHMS32_native_installed() { + + bool rst = false; + if (this->GetOSArchitecture() == "32-bit") { + LPCTSTR pszSubkey = L"SOFTWARE\\hMailServer"; + HKEY hKey = HKEY_LOCAL_MACHINE; + + HKEY subKey = nullptr; + LONG result = RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey); + if (result != ERROR_SUCCESS) + rst = false; + else + rst = true; + } + return rst; + +} + +bool Sysutils::IsHMS64_native_installed() { + + bool rst = false; + + if (this->GetOSArchitecture() == "64-bit") { + + LPCTSTR pszSubkey = L"SOFTWARE\\Wow6432Node\\hMailServer"; + HKEY hKey = HKEY_LOCAL_MACHINE; + + HKEY subKey = nullptr; + if (!(RegOpenKeyEx(hKey, pszSubkey, 0, KEY_READ, &subKey) != ERROR_SUCCESS)) { + + LPCWSTR pszValueName = L"InstallLocation"; + pszSubkey = L"SOFTWARE\\Wow6432Node\\hMailServer"; + + if (RegOpenKey(HKEY_LOCAL_MACHINE, pszSubkey, &hKey) != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + // Buffer to store string read from registry + TCHAR szValue[1024]; + DWORD cbValueLength = sizeof(szValue); + + // Query string value + if (RegQueryValueEx( + hKey, + pszValueName, + nullptr, + nullptr, + reinterpret_cast(&szValue), + &cbValueLength) + != ERROR_SUCCESS) { + AtlThrowLastWin32(); + } + + CString wrkstr = szValue; + wrkstr = wrkstr + L"\\Bin\\hMailServer.exe"; + + if (this->GetBinaryBitness(wrkstr) == "64-Bit (x64)") + rst = true; + } + } + return rst; +} + +// Get the used type of Database +CString Sysutils::GetSQLDatabaseType(CString iniFilepath) +{ + string cfilename = iniFilepath+"\\Bin\\hMailServer.INI"; + ifstream fileInput; + string line; + char* search = "Type="; + string result; + + fileInput.open(cfilename.c_str()); + if (fileInput.is_open()) { + unsigned int curLine = 0; + while (getline(fileInput, line)) { + curLine++; + if (line.find(search, 0) != string::npos) { + result = line; + } + } + fileInput.close(); + } + + CString wrkx = CA2T(result.c_str()); + return wrkx; +} + +// Check if we are running inside VirtualBox Guestsystem or not +CString Sysutils::GetIsVirtualBox() +{ + if (CreateFile(L"\\\\.\\VBoxMiniRdrDN", GENERIC_READ, FILE_SHARE_READ, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr) != INVALID_HANDLE_VALUE) { + return (L"Virtualbox Guest Environment detected!"); + } else { + return (L"No Virtualmachine detected"); + } + +} +// Check Windows Service Status +char* Sysutils::getServiceStatus() +{ + TCHAR szSvcName[80] = L"hMailServer"; + SERVICE_STATUS_PROCESS ssp; + DWORD dwBytesNeeded; + char* iReturn = nullptr; + + SC_HANDLE schSCManager = OpenSCManager( + nullptr, // local computer + nullptr, // ServicesActive database + SC_MANAGER_QUERY_LOCK_STATUS); // full access rights + + if (nullptr == schSCManager) { + } + + // Get a handle to the service. + SC_HANDLE schService = OpenService( + schSCManager, // SCM database + szSvcName, // name of service + SERVICE_QUERY_STATUS ); + + if (schService == nullptr) + { + CloseServiceHandle(schSCManager); + } + + // Make sure the service is not already stopped. + if (!QueryServiceStatusEx( + schService, + SC_STATUS_PROCESS_INFO, + (LPBYTE)&ssp, + sizeof(SERVICE_STATUS_PROCESS), + &dwBytesNeeded)) + { + iReturn = "Error! Cannot access Servicedata"; + } + + if (ssp.dwCurrentState == SERVICE_STOPPED) { + iReturn = "stopped"; + } + + if (ssp.dwCurrentState == SERVICE_RUNNING) { + iReturn = "running"; + } + + CloseServiceHandle(schService); + CloseServiceHandle(schSCManager); + + return iReturn; +} + +// Check Windows the Username for the Service Status +CString Sysutils::GetServiceAccountName() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT startname FROM Win32_Service"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"startname", 0, &vtProp, nullptr, nullptr); + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +// Check Windows hMailServer Service Startmode +CString Sysutils::GetServiceStartMode() +{ + HRESULT hres; + + hres = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + if (FAILED(hres)) {} + + hres = CoInitializeSecurity( + nullptr, + -1, + nullptr, + nullptr, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, + EOAC_NONE, + nullptr + ); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemLocator *pLoc = nullptr; + + hres = CoCreateInstance( + CLSID_WbemLocator, + nullptr, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&pLoc); + + if (FAILED(hres)) { + CoUninitialize(); + } + + IWbemServices *pSvc = nullptr; + + hres = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + nullptr, // User name. NULL = current user + nullptr, // User password. NULL = current + nullptr, // Locale. NULL indicates current + 0, // Security flags. + nullptr, // Authority (for example, Kerberos) + nullptr, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if (FAILED(hres)) { + pLoc->Release(); + CoUninitialize(); + } + + hres = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + nullptr, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + nullptr, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery( + bstr_t("WQL"), + bstr_t("SELECT startmode FROM Win32_Service"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + nullptr, + &pEnumerator); + + if (FAILED(hres)) { + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + } + + IWbemClassObject *pclsObj = nullptr; + ULONG uReturn = 0; + + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + VARIANT vtProp; + pclsObj->Get(L"startmode", 0, &vtProp, nullptr, nullptr); + CString result = vtProp.bstrVal; + VariantClear(&vtProp); + pclsObj->Release(); + + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + CoUninitialize(); + return result; +} + +Sysutils::~Sysutils() +{ +} diff --git a/HMSInfo/Sysutils.h b/HMSInfo/Sysutils.h new file mode 100644 index 0000000..ebca43d --- /dev/null +++ b/HMSInfo/Sysutils.h @@ -0,0 +1,58 @@ +#pragma once +#include +#include + +using namespace std; + +class Sysutils +{ +public: + Sysutils(); + int gBitness; + CString GetHMS32WOW64VersionInfo(); + CString GetHMS64VersionInfo(); + int GetTotalAvaiableMemory(); + + int GetFreeMemory(); + CString GetOSDesc(); + CString GetCPUInfo(); + CString GetNicInfo(); + int GetNicSpeed(); + CString GetNicIsEnabled(); + CString GetNicConnectionID(); + CString GetDNSInfo(); + CString GetMacAddress(); + CString GetDefaultGateWay(); + CString GetDNSServers(); + CString GetTimestamp(); + CString GetMemoryInUse(); + CString GetOSArchitecture(); + CString GetBinaryBitness(LPCTSTR lpApplicationName); + int GetMyBitness(); + int GetOSServicePack(); + int GetOSBuild(); + CString GetOSBuildEx(); + int GetCPUCores(); + int MaxProcessMemorySize(); + CString GetHMS32WOW64InstallPath(); + CString GetHMS64InstallPath(); + CString GetHMS32InstallPath(); + CString GetHMS32InstallDate(); + CString GetHMS64NativeVersionInfo(); + CString GetHMS32NativeVersionInfo(); + CString GetHMSInfoPath(); + BOOL IsWow64(); + bool IsNative64Bit(); + bool IsHMS32_WOW64_Installed(); + bool IsHMS32_native_installed(); + bool IsHMS64_native_installed(); + CString GetSQLDatabaseType(CString iniFilepath); + CString GetIsVirtualBox(); + int GetHMSBitness(); + char* getServiceStatus(); + CString GetServiceAccountName(); + CString GetServiceStartMode(); + + ~Sysutils(); +}; + diff --git a/HMSInfo/hMailServerInfo.cpp b/HMSInfo/hMailServerInfo.cpp new file mode 100644 index 0000000..75e6afb --- /dev/null +++ b/HMSInfo/hMailServerInfo.cpp @@ -0,0 +1,366 @@ +// hMailServerInfo.cpp : implementation file + +#include "stdafx.h" +#include "hMailServer.h" +#include +#include "HMSInfo.h" +#include "hMailServerInfo.h" +#include +#include +#include + +IMPLEMENT_DYNAMIC(hMailServerInfo, CWnd) + +hMailServerInfo::hMailServerInfo() +{ +} + +hMailServerInfo::~hMailServerInfo() +{ +} + +BEGIN_MESSAGE_MAP(hMailServerInfo, CWnd) +END_MESSAGE_MAP() + +/* COM - Get hMailServer Version */ +CString hMailServerInfo::Version() +{ + + HRESULT hr; + IInterfaceApplication *app; + BSTR pVal = nullptr; + + hr = CoInitialize(nullptr); + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&app); + + app->get_Version(&pVal); + app->Release(); + } + + return (pVal); +} + +// COM - Returns Max Delivery Threads +int hMailServerInfo::MaxDeliveryThreads(CString pUsr, CString pPwd) +{ + + long pVal = 0; + + try { + + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceSettings *pSettings; + oApp->get_Settings(&pSettings); + + pSettings->get_MaxDeliveryThreads(&pVal); + + } + else { + AfxMessageBox(L"Login wrong, try again"); + } + + + } + + oApp->Release(); + + } + + catch (std::exception & stdExp) // sample exception handler + { + // Show error message + ::MessageBoxA(nullptr, stdExp.what(), "hMailServer reported a internal error", MB_ICONEXCLAMATION | MB_OK); + + return 1; // return to exit the application + + } + catch (...) // catches exception of types not caught above + { + pVal = 0; + ::MessageBoxA(nullptr, "hMailServer reported a fatal error", "Fatal Error", MB_ICONEXCLAMATION | MB_OK); + + return 1; // return to exit the application + + } + + return pVal; +} + +// Query processed messages +int hMailServerInfo::ProcessedMessages(CString pUsr, CString pPwd) +{ + long pVal = 0; + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceStatus *pStatus; + oApp->get_Status(&pStatus); + pStatus->get_ProcessedMessages(&pVal); + + + } + } + oApp->Release(); + return pVal; +} + +// Query processed messages +int hMailServerInfo::getUndeliveredMessages(CString pUsr, CString pPwd) +{ + BSTR pVal; + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceStatus *pStatus; + oApp->get_Status(&pStatus); + pStatus->get_UndeliveredMessages(&pVal); + + } + } + oApp->Release(); + return 0; +} + +// COM Query hMailServer Startuptime +CString hMailServerInfo::StartTime(CString pUsr, CString pPwd) +{ + BSTR pVal = nullptr; + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceStatus *pStatus; + oApp->get_Status(&pStatus); + pStatus->get_StartTime(&pVal); + } + } + oApp->Release(); + return pVal; +} + +// COM Query connect SMTP-Clients +int hMailServerInfo::UserSessions(CString pUsr, CString pPwd) +{ + long pVal = 0; + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceStatus *pStatus; + oApp->get_Status(&pStatus); + pStatus->get_SessionCount(eSTSMTPClient, &pVal); + } + } + oApp->Release(); + return pVal; +} + + +// COM Query hMailServer Startuptime +CString hMailServerInfo::IsDBConnected(CString pUsr, CString pPwd) +{ + VARIANT_BOOL pVal = VARIANT_FALSE; + CString iState; + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceDatabase *pDatabase; + oApp->get_Database(&pDatabase); + pDatabase->get_IsConnected(&pVal); + + + if (pVal == VARIANT_TRUE) { + iState = "Connected to SQL-Database"; + } + else { + iState = "NOT connected to SQL-Database"; + } + } + + oApp->Release(); + + } + return iState; +} + +// COM Query hMailServer Startuptime +CString hMailServerInfo::getClientConnectedName(CString pUsr, CString pPwd) +{ + + + + try { + + HRESULT hr; + IInterfaceApplication *oApp = nullptr; + + hr = CoInitialize(nullptr); + + if (SUCCEEDED(hr)) { + CoCreateInstance( + CLSID_Application, + nullptr, + CLSCTX_LOCAL_SERVER, + IID_IInterfaceApplication, + (void**)&oApp); + + BSTR usr = SysAllocString((_bstr_t)pUsr); + BSTR pwd = SysAllocString((_bstr_t)pPwd); + IInterfaceAccount *pAcc; + + oApp->Authenticate(usr, pwd, &pAcc); + + if (pAcc) { + IInterfaceUtilities * pUtilities; + oApp->get_Utilities(&pUtilities); + + + + + + CString tmp; + //tmp.Format(foo); + + //AfxMessageBox(foo); + + + + /* BSTR a = nullptr;*/ + /* pClient->get_Username(&a);*/ + + // pSettings->get_MaxDeliveryThreads(&pVal); + + } + else { + AfxMessageBox(L"Login wrong, try again"); + } + + } + oApp->Release(); + } + + catch (std::exception & stdExp) // sample exception handler + { + // Show error message + ::MessageBoxA(nullptr, stdExp.what(), "hMailServer reported a internal error", MB_ICONEXCLAMATION | MB_OK); + + } + catch (...) // catches exception of types not caught above + { + ::MessageBoxA(nullptr, "hMailServer reported a fatal error", "Fatal Error", MB_ICONEXCLAMATION | MB_OK); + + } + + // return (CString)pVal); + return nullptr; +} + diff --git a/HMSInfo/hMailServerInfo.h b/HMSInfo/hMailServerInfo.h new file mode 100644 index 0000000..a653973 --- /dev/null +++ b/HMSInfo/hMailServerInfo.h @@ -0,0 +1,29 @@ +#pragma once + + +// hMailServerInfo + +class hMailServerInfo : public CWnd +{ + DECLARE_DYNAMIC(hMailServerInfo) + +public: + hMailServerInfo(); + virtual ~hMailServerInfo(); + CString Version(); + +protected: + DECLARE_MESSAGE_MAP() + +public: + // Prototypes + int MaxDeliveryThreads(CString pUsr, CString pPwd); + int ProcessedMessages(CString pUsr, CString pPwd); + int getUndeliveredMessages(CString pUsr, CString pPwd); + CString StartTime(CString pUsr, CString pPwd); + int UserSessions(CString pUsr, CString pPwd); + CString IsDBConnected(CString pUsr, CString pPwd); + CString getClientConnectedName(CString pUsr, CString pPwd); +}; + + diff --git a/HMSInfo/ipenum.cpp b/HMSInfo/ipenum.cpp new file mode 100644 index 0000000..6e37181 --- /dev/null +++ b/HMSInfo/ipenum.cpp @@ -0,0 +1,82 @@ +#include "stdafx.h" +#include "ipenum.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +CIPEnum::CIPEnum() +{ + m_bWinsockInitialied = FALSE; + + //Initialise the winsock stack + WORD wVersionRequested = MAKEWORD(1, 1); + WSADATA wsaData; + int err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) + { + TRACE(_T("Failed in call to WSAStartup, return value was %d\n"), err); + AfxThrowNotSupportedException(); + } + + //remember that we have opened winsock + m_bWinsockInitialied = TRUE; + + //Code requires at least Winsock 1.1 + if ((LOBYTE(wsaData.wVersion) != 1) || (HIBYTE(wsaData.wVersion) != 1)) + { + TRACE(_T("Failed to find a usable winsock stack which supports Winsock 1.1\n")); + AfxThrowNotSupportedException(); + } +} + + +CIPEnum::~CIPEnum() +{ + //release our use of winsock stack if we successfully initialised it + if (m_bWinsockInitialied) + WSACleanup(); +} + + +BOOL CIPEnum::Enumerate() +{ + //get this machines host name + char szHostname[256]; + if (gethostname(szHostname, sizeof(szHostname))) + { + TRACE(_T("Failed in call to gethostname, WSAGetLastError returns %d\n"), WSAGetLastError()); + return FALSE; + } + + //get host information from the host name + HOSTENT* pHostEnt = gethostbyname(szHostname); + if (pHostEnt == nullptr) + { + TRACE(_T("Failed in call to gethostbyname, WSAGetLastError returns %d\n"), WSAGetLastError()); + return FALSE; + } + + //check the length of the IP adress + if (pHostEnt->h_length != 4) + { + TRACE(_T("IP address returned is not 32 bits !!\n")); + return FALSE; + } + + //call the virtual callback function in a loop + int nAdapter = 0; + BOOL bContinue = TRUE; + while (pHostEnt->h_addr_list[nAdapter] && bContinue) + { + in_addr address; + CopyMemory(&address.S_un.S_addr, pHostEnt->h_addr_list[nAdapter], pHostEnt->h_length); + bContinue = EnumCallbackFunction(nAdapter, address); + nAdapter++; + } + + return TRUE; +} diff --git a/HMSInfo/ipenum.h b/HMSInfo/ipenum.h new file mode 100644 index 0000000..30a4f55 --- /dev/null +++ b/HMSInfo/ipenum.h @@ -0,0 +1,25 @@ + +#ifndef __IPENUM_H__ +#define __IPENUM_H__ + + + +class CIPEnum +{ +public: +//constructors / Destructors + CIPEnum(); + virtual ~CIPEnum(); + +//methods + BOOL Enumerate(); + +protected: + virtual BOOL EnumCallbackFunction(int nAdapter, const in_addr& address) = 0; + BOOL m_bWinsockInitialied; +}; + + + + +#endif //__IPENUM_H__ \ No newline at end of file diff --git a/HMSInfo/res/HMSInfo.ico b/HMSInfo/res/HMSInfo.ico new file mode 100644 index 0000000..e74f7b2 Binary files /dev/null and b/HMSInfo/res/HMSInfo.ico differ diff --git a/HMSInfo/res/HMSInfo.rc2 b/HMSInfo/res/HMSInfo.rc2 new file mode 100644 index 0000000..2c04c34 Binary files /dev/null and b/HMSInfo/res/HMSInfo.rc2 differ diff --git a/HMSInfo/res/keys.bmp b/HMSInfo/res/keys.bmp new file mode 100644 index 0000000..546e8b1 Binary files /dev/null and b/HMSInfo/res/keys.bmp differ diff --git a/HMSInfo/resource.h b/HMSInfo/resource.h new file mode 100644 index 0000000..a71ee8c Binary files /dev/null and b/HMSInfo/resource.h differ diff --git a/HMSInfo/stdafx.cpp b/HMSInfo/stdafx.cpp new file mode 100644 index 0000000..9b97952 --- /dev/null +++ b/HMSInfo/stdafx.cpp @@ -0,0 +1,6 @@ +#include "stdafx.h" +//.. + + + + diff --git a/HMSInfo/stdafx.h b/HMSInfo/stdafx.h new file mode 100644 index 0000000..dda67df --- /dev/null +++ b/HMSInfo/stdafx.h @@ -0,0 +1,42 @@ +#pragma once + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit + +// turns off MFC's hiding of some common and often safely ignored warning messages +//.. +#define _AFX_ALL_WARNINGS + +#include // MFC core and standard components +#include // MFC extensions + + +#include // MFC Automation classes + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC support for Internet Explorer 4 Common Controls +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // MFC support for ribbons and control bars + + +#include // MFC socket extensions + + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + + diff --git a/HMSInfo/targetver.h b/HMSInfo/targetver.h new file mode 100644 index 0000000..90e767b --- /dev/null +++ b/HMSInfo/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/HMSInfo/versioninfo.cpp b/HMSInfo/versioninfo.cpp new file mode 100644 index 0000000..ab7ca05 --- /dev/null +++ b/HMSInfo/versioninfo.cpp @@ -0,0 +1,151 @@ +#include "stdafx.h" +#include "versioninfo.h" + +#ifndef _WIN32_WCE +#pragma comment (lib, "Version.lib") +#endif + + +CVersionInfo::CVersionInfo(LPCTSTR lpAppName) +{ + // Initialize member variables: + ASSERT(lpAppName); + Initialize(lpAppName); +} + +CVersionInfo::CVersionInfo(HINSTANCE hInst) +{ + // Define buffer for application name: + TCHAR szAppName[_MAX_PATH + 1]; + + // Get the application name (name of .exe file): + if (!GetModuleFileName(hInst, szAppName, _countof(szAppName))) + { + // Failed to get name. Set string to NULL and return: + TRACE(_T("GetModuleFileName () failed, OS Error == %08X\n"), GetLastError()); + ZeroMemory(&m_stFixedInfo, sizeof(m_stFixedInfo)); + return; + } + + // Initialize member variables: + Initialize(szAppName); +} + +void CVersionInfo::Initialize(LPCTSTR szAppName) +{ + ASSERT(szAppName); + + // Initialize fixed info structure: + ZeroMemory(&m_stFixedInfo, sizeof(m_stFixedInfo)); + + // Load the Version information + // Load signon Version information + DWORD dwHandle; + DWORD dwSize; + + // Determine the size of the VERSIONINFO resource: + if (!((dwSize = GetFileVersionInfoSize((LPTSTR)szAppName, &dwHandle)))) + { + TRACE(_T("GetFileVesionInfoSize () failed on %s"), szAppName); + return; + } + + // Declare pointer to Version info resource: + LPBYTE lpVerInfo = nullptr; + +#ifdef _WIN32_WCE + TRY +#else + try +#endif + { + // Allocate memory to hold Version info: + lpVerInfo = new BYTE[dwSize]; + + // Read the VERSIONINFO resource from the file: + if (GetFileVersionInfo((LPTSTR)szAppName, dwHandle, dwSize, lpVerInfo)) + { + VS_FIXEDFILEINFO *lpFixedInfo; + LPCTSTR lpText; + UINT uSize; + + // Read the FILE DESCRIPTION: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\FileDescription"), (void **)&lpText, &uSize)) + m_strDescription = lpText; + + // Read additional comment: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\Comments"), (void **)&lpText, &uSize)) + m_strComments = lpText; + + // Read company name: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\CompanyName"), (void **)&lpText, &uSize)) + m_strCompany = lpText; + + // Read product name: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\ProductName"), (void **)&lpText, &uSize)) + m_strProductName = lpText; + + // Read internal name: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\InternalName"), (void **)&lpText, &uSize)) + m_strInternalName = lpText; + + // Read legal copyright: + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\LegalCopyright"), (void **)&lpText, &uSize)) + m_strLegalCopyright = lpText; + + // Read file Version + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\FileVersion"), (void **)&lpText, &uSize)) + m_strFileVersion = lpText; + + // Read product Version + if (VerQueryValue(lpVerInfo, _T("\\StringFileInfo\\040904B0\\ProductVersion"), (void **)&lpText, &uSize)) + m_strProductVersion = lpText; + + + + // Read the FIXEDINFO portion: + if (VerQueryValue(lpVerInfo, _T("\\"), (void **)&lpFixedInfo, &uSize)) + m_stFixedInfo = *lpFixedInfo; + } + } + + // Handle exceptions: +#ifdef _WIN32_WCE + CATCH(CException, e) + { + e->Delete(); +#else + catch (...) + { +#endif + // EXCEPTIONMSG(); + } + +#ifdef _WIN32_WCE + END_CATCH +#endif + + // Free memory allocated for Version info: + delete[] lpVerInfo; + } + +void CVersionInfo::Format(CString &strOutput) +{ + // Append Version number information to the sign on string: + strOutput.Format(_T("V%d.%d%d.%d"), + HIWORD(m_stFixedInfo.dwFileVersionMS), + LOWORD(m_stFixedInfo.dwFileVersionMS), + HIWORD(m_stFixedInfo.dwFileVersionLS), + LOWORD(m_stFixedInfo.dwFileVersionLS)); + + // Add UNICODE tag: +#ifndef _WIN32_WCE +#ifdef _UNICODE + strOutput += _T(" - U"); +#endif +#endif + + // include a debug indication: + if (m_stFixedInfo.dwFileFlags & VS_FF_DEBUG) + strOutput += _T(" (Debug)"); +} \ No newline at end of file diff --git a/HMSInfo/versioninfo.h b/HMSInfo/versioninfo.h new file mode 100644 index 0000000..6daddfd --- /dev/null +++ b/HMSInfo/versioninfo.h @@ -0,0 +1,47 @@ +#ifndef _VERSIONINFO_H +#define _VERSIONINFO_H +#include "stdafx.h" +//#include + + +// ************************************************************************** +class CVersionInfo +{ +public: + CVersionInfo(LPCTSTR lpszAppName); // If you know the filename + CVersionInfo(HINSTANCE hInst); // If the file is in memory + + WORD GetMajorVersion() { return (HIWORD(m_stFixedInfo.dwFileVersionMS)); } + WORD GetMinorVersion() { return (LOWORD(m_stFixedInfo.dwFileVersionMS)); } + WORD GetBuildNumber() { return (LOWORD(m_stFixedInfo.dwFileVersionLS)); } + + LPCTSTR GetDescription() { return (m_strDescription); } + LPCTSTR GetComments() { return (m_strComments); } + LPCTSTR GetCompany() { return (m_strCompany); } + LPCTSTR GetProductName() { return (m_strProductName); } + LPCTSTR GetInternalName() { return (m_strInternalName); } + LPCTSTR GetLegalCopyright() { return (m_strLegalCopyright); } + LPCTSTR GetFileversion() { return (m_strFileVersion); } + LPCTSTR GetProductVersion() { return (m_strProductVersion); } + + + void Format(CString &strOutput); + + const VS_FIXEDFILEINFO &GetFixedInfo() { return (m_stFixedInfo); } + +protected: + void Initialize(LPCTSTR lpszAppName); + + VS_FIXEDFILEINFO m_stFixedInfo; + CString m_strDescription; + CString m_strComments; + CString m_strCompany; + CString m_strProductName; + CString m_strInternalName; + CString m_strLegalCopyright; + CString m_strFileVersion; + CString m_strProductVersion; +}; + + +#endif // _VERSIONINFO_H