📄 ntautologondlg.cpp
字号:
// NTAutoLogonDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NTAutoLogon.h"
#include "NTAutoLogonDlg.h"
#include "Mimadlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNTAutoLogonDlg dialog
CNTAutoLogonDlg::CNTAutoLogonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNTAutoLogonDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNTAutoLogonDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNTAutoLogonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNTAutoLogonDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNTAutoLogonDlg, CDialog)
//{{AFX_MSG_MAP(CNTAutoLogonDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BTN_ENABLE, OnBtnEnable)
ON_BN_CLICKED(IDC_BTN_DISABLE, OnBtnDisable)
ON_BN_CLICKED(IDC_BTN_EXIT, OnBtnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNTAutoLogonDlg message handlers
BOOL CNTAutoLogonDlg::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
// m_BrushBK.CreateSolidBrush(RGB(255,255,207));
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 CNTAutoLogonDlg::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 CNTAutoLogonDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
HBRUSH CNTAutoLogonDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
pDC->SetBkColor(RGB(255,255,207));
return (HBRUSH)(m_BrushBK.GetSafeHandle());
}
void CNTAutoLogonDlg::OnBtnEnable()
{
HKEY hkey;
TCHAR g_pcszValue[] = _T("1");
CMimaDlg dlg;
if(dlg.DoModal() != IDOK)
{
return;
}
TCHAR * g_pcszMima =(TCHAR *) new char[dlg.m_strMima.GetLength()];
g_pcszMima = _T(dlg.m_strMima.GetBuffer(dlg.m_strMima.GetLength()));
if( RegOpenKey( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\WinLogon"), &hkey ) == ERROR_SUCCESS )
{
if( !RegSetValueEx( hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszValue), sizeof( g_pcszValue ) / sizeof( g_pcszValue[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
return;
}
if( !RegSetValueEx( hkey, _T("DefaultPassword"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszMima), sizeof( g_pcszMima ) / sizeof( g_pcszMima[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
TCHAR pcszValue[] = _T("0");
RegSetValueEx( hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(pcszValue), sizeof( pcszValue ) / sizeof( pcszValue[0] ) );
}
else
AfxMessageBox("设定成功!重新启动即可生效!\r\n 请注意系统安全!");
}
else
{
AfxMessageBox("设定失败!");
}
}
void CNTAutoLogonDlg::OnBtnDisable()
{
HKEY hkey;
TCHAR g_pcszValue[] = _T("0");
if( RegOpenKey( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"), &hkey ) == ERROR_SUCCESS )
{
if( !RegSetValueEx( hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszValue), sizeof( g_pcszValue ) / sizeof( g_pcszValue[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
}
else
AfxMessageBox("设定成功!重新启动即可生效!\r\n 请注意系统安全!");
}
else
{
AfxMessageBox("设定失败!");
}
}
void CNTAutoLogonDlg::OnBtnExit()
{
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -