// RasdetectcodeguruDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Rasdetectcodeguru.h"
#include "RasdetectcodeguruDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRasdetectcodeguruDlg dialog
CRasdetectcodeguruDlg::CRasdetectcodeguruDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRasdetectcodeguruDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRasdetectcodeguruDlg)
m_output = _T("Press 'detect' to start the detection.");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRasdetectcodeguruDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRasdetectcodeguruDlg)
DDX_Text(pDX, IDC_OUTPUT, m_output);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRasdetectcodeguruDlg, CDialog)
//{{AFX_MSG_MAP(CRasdetectcodeguruDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRasdetectcodeguruDlg message handlers
BOOL CRasdetectcodeguruDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRasdetectcodeguruDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) 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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRasdetectcodeguruDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRasdetectcodeguruDlg::OnOK() {
int result = 0;
result = RasDetect();
if(result == -666) m_output = "Unable to detect your OS and OS version.";
else if(result == -1) m_output = "Unable to open the desired registry keys.";
else if(result == 0) m_output = "There is no RAS installed.";
else if(result == 1) m_output = "You have RAS installed.";
else m_output = "Wow! You managed to get an impossible result!!\r\nCongratulations.";
UpdateData(false);
}
int RasDetect(void) {
HKEY registry = NULL;;
DWORD result;
OSVERSIONINFO version;
char regkey[70];
/* First we have to find out which OS we are running on */
version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
/* If we get and error, we can't continue. */
if(!GetVersionEx(&version)) return -666;
/* Then we set the registry key we want to look at, according to the OS we detected. */
if(version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) strcpy(regkey,"system\\currentcontrolset\\services\\remoteaccess\\networkprovider");
else if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) strcpy(regkey,"system\\currentcontrolset\\services\\remoteaccess");
/* We then try to open the registry key */
if((result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,regkey,0,STANDARD_RIGHTS_READ|KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS|KEY_NOTIFY|READ_CONTROL,®istry)) != ERROR_SUCCESS) {
/* If we have NO success, but also not 'file not found error', we have encountered another error. */
if(result != ERROR_FILE_NOT_FOUND) {
RegCloseKey(registry);
return -1;
/* Else we got an error and it was the 'file not found', telling us that that registry */
/* key does not exist and we can conclude that the RAS has not been installed. */
} else {
RegCloseKey(registry);
return 0;
}
}
/* If all goes well, we find the key we were looking for. This tells us that there is */
/* RAS installed on this machine. */
RegCloseKey(registry);
return 1;
}