註冊表註入RegInject(dll)
阿新 • • 發佈:2018-10-20
ESS cst 註冊 string value domo dal dll 鏈接 // RegInject.h
#pragma once // RegInject 對話框 class RegInject : public CDialogEx { DECLARE_DYNAMIC(RegInject) public: RegInject(CWnd* pParent = NULL); // 標準構造函數 virtual ~RegInject(); // 對話框數據 enum { IDD = IDD_DIALOG6 }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: CString m_strDllPath; afx_msg void OnBnClickedButton1(); afx_msg void OnBnClickedButton2(); };
// RegInject.cpp
// RegInject.cpp : 實現文件 // #include "stdafx.h" #include "MyInjectTool.h" #include "RegInject.h" #include "afxdialogex.h" // RegInject 對話框 IMPLEMENT_DYNAMIC(RegInject, CDialogEx) RegInject::RegInject(CWnd* pParent /*=NULL*/) : CDialogEx(RegInject::IDD, pParent) , m_strDllPath(_T("")) { } RegInject::~RegInject() { } void RegInject::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT1, m_strDllPath); } BEGIN_MESSAGE_MAP(RegInject, CDialogEx) ON_BN_CLICKED(IDC_BUTTON1, &RegInject::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &RegInject::OnBnClickedButton2) END_MESSAGE_MAP() // RegInject 消息處理程序 void RegInject::OnBnClickedButton1() { // TODO: 在此添加控件通知處理程序代碼 char szFilter[] = "動態鏈接庫|*.dll"; CFileDialog fileDlg(TRUE, "dll", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); UpdateData(TRUE); if (fileDlg.DoModal() == IDOK) { m_strDllPath = fileDlg.GetPathName(); } UpdateData(FALSE); } void RegInject::OnBnClickedButton2() { // TODO: 在此添加控件通知處理程序代碼 BOOL bRet = FALSE; HKEY hKey = NULL; LONG nReg; char szDllPath[MAX_PATH] = { 0 }; //打開HKEY_LOCAL_MACHINE/Software/Microsoft/WindowsNT/CurrentVersion/Windows nReg = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows", 0, KEY_ALL_ACCESS, &hKey); if (nReg != ERROR_SUCCESS) { MessageBox("打開註冊表失敗"); RegCloseKey(hKey); return; } //設置AppInit_DLLs的鍵值為我們的Dll nReg = RegSetValueEx(hKey, "AppInit_DLLs", 0, REG_SZ, //(byte *)m_strDllPath.GetBuffer(0), NULL, m_strDllPath.GetLength() ); if (nReg != ERROR_SUCCESS) { MessageBox("設置註冊表失敗!"); RegCloseKey(hKey); return; } RegCloseKey(hKey); return; }
註冊表註入RegInject(dll)