installform.cpp

来自「实现了隐藏进程,使进程对任务管理器和进程查看器均不可见,使文件对资源管理器不可见」· C++ 代码 · 共 172 行

CPP
172
字号
// InstallForm.cpp : implementation file
//

#include "stdafx.h"
#include "GUI.h"
#include "InstallForm.h"


// InstallForm

IMPLEMENT_DYNCREATE(InstallForm, CFormView)

BEGIN_MESSAGE_MAP(InstallForm, CFormView)
	ON_BN_CLICKED(IDC_BUT_PATH_SELECT, OnBnClickedButPathSelect)
	ON_BN_CLICKED(IDC_BUT_INST, OnBnClickedButInst)
	ON_BN_CLICKED(IDC_BUT_UNINST, OnBnClickedButUninst)
	ON_BN_CLICKED(IDC_BUT_RUN, OnBnClickedButRun)
	ON_BN_CLICKED(IDC_BUT_STOP, OnBnClickedButStop)
END_MESSAGE_MAP()

InstallForm::InstallForm()
	: CFormView(InstallForm::IDD)
{
}

InstallForm::~InstallForm()
{
}

void InstallForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
}

void InstallForm::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	SetDlgItemText(IDC_EDIT_PATH,_T("C:\\DriverDev\\HideDriver.sys"));
	SetDlgItemText(IDC_EDIT_NAME,_T("HideDriver"));
	SetDlgItemText(IDC_COMBO_TYPE,_T("SERVICE_DEMAND_START"));
}

// InstallForm message handlers
void InstallForm::OnBnClickedButPathSelect()
{
	CFileDialog fl_dlg(true);
	if(fl_dlg.DoModal() != IDOK )
		return;

	CString file_path=fl_dlg.GetPathName();

	SetDlgItemText(IDC_EDIT_PATH,file_path);
	SetDlgItemText(IDC_EDIT_NAME,_T(""));
}
// Driver installation
void InstallForm::OnBnClickedButInst()
{
	CString strName,strPath,strStartType;
	DWORD startType;
	// Get input parameters
	GetDlgItemText(IDC_EDIT_PATH,strPath);
	if(strPath.GetLength() == NULL)
	{
		AfxMessageBox(_T("Path is empty"));
		return;
	}
	GetDlgItemText(IDC_EDIT_NAME,strName);
	if(strName.GetLength() == NULL)
	{
		AfxMessageBox(_T("Name is empty"));
		return;
	}
	GetDlgItemText(IDC_COMBO_TYPE,strStartType);
	if(strStartType == _T("SERVICE_AUTO_START"))
		startType = SERVICE_AUTO_START;
	else if(strStartType == _T("SERVICE_BOOT_START"))
		startType = SERVICE_BOOT_START;
	else if(strStartType == _T("SERVICE_DEMAND_START"))
		startType = SERVICE_DEMAND_START;
	else if(strStartType == _T("SERVICE_DISABLED"))
		startType = SERVICE_DISABLED;
	else if(strStartType == _T("SERVICE_SYSTEM_START"))
		startType = SERVICE_SYSTEM_START;
	else
	{
		AfxMessageBox(_T("Wrong start type"));
		return;
	}

	// Try to install driver
	BOOL res = mDrvWork.Install(strName,strPath,startType);
	if(!res) // But they can be installed early
		SetDlgItemText(IDC_STATIC_STATUS,_T("Cannot install"));
	else
		SetDlgItemText(IDC_STATIC_STATUS,_T("Installed"));
}
void InstallForm::OnBnClickedButUninst()
{
	CString strName,strPath;
	// Get input parameters
	GetDlgItemText(IDC_EDIT_PATH,strPath);
	if(strPath.GetLength() == NULL)
	{
		AfxMessageBox(_T("Path is empty"));
		return;
	}
	GetDlgItemText(IDC_EDIT_NAME,strName);
	if(strName.GetLength() == NULL)
	{
		AfxMessageBox(_T("Name is empty"));
		return;
	}

	BOOL res = mDrvWork.Remove(strName,strPath);
	if(!res) 
		SetDlgItemText(IDC_STATIC_STATUS,_T("Cannot uninstall"));
	else
		SetDlgItemText(IDC_STATIC_STATUS,_T("Uninstaled"));
}

// Driver control
void InstallForm::OnBnClickedButRun()
{
	CString strName;
	// Get input parameters
	GetDlgItemText(IDC_EDIT_NAME,strName);
	if(strName.GetLength() == NULL)
	{
		AfxMessageBox(_T("Name is empty"));
		return;
	}

	BOOL res = mDrvWork.Start(strName);
	if(!res) 
		SetDlgItemText(IDC_STATIC_STATUS,_T("Cannot start"));
	else
		SetDlgItemText(IDC_STATIC_STATUS,_T("Started"));
}

void InstallForm::OnBnClickedButStop()
{	
	CString strName;
	// Get input parameters
	GetDlgItemText(IDC_EDIT_NAME,strName);
	if(strName.GetLength() == NULL)
	{
		AfxMessageBox(_T("Name is empty"));
		return;
	}

	BOOL res = mDrvWork.Stop(strName);
	if(!res) 
		SetDlgItemText(IDC_STATIC_STATUS,_T("Cannot stop"));
	else
		SetDlgItemText(IDC_STATIC_STATUS,_T("Stoped"));
}

// InstallForm diagnostics

#ifdef _DEBUG
void InstallForm::AssertValid() const
{
	CFormView::AssertValid();
}

void InstallForm::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?