一、创建对话框应用程序
二、编辑对话框资源
控件ID与标题
IDC_REGVALUE [编辑]
ID_READ 读取
ID_WRITE 隐藏
ID_SHOW 显示
三、添加变量、函数
1、添加变量
2、添加函数
四、添加代码
1、添加包含语句
// RegRandDlg.cpp : implementation file
#include "stdafx.h"
#include "RegRand.h"
#include "RegRandDlg.h"
#include <atlbase.h>
2、添加函数代码
void CRegRandDlg::OnRead()
{
// TODO: Add your control notification handler code here
CString strPath="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";//注册表子键名
CRegKey regkey;//注册表类对象
LONG lResult;//返回成功类型
lResult=regkey.Open(HKEY_CURRENT_USER,LPCTSTR(strPath),KEY_ALL_ACCESS);//打开注册表主键
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法打开有关的注册表信息");
return;
}
DWORD dwValue;
lResult=regkey.QueryValue(dwValue,LPCTSTR("NoDriveTypeAutoRun"));//读取RegisteredOwner字段
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法查询有关的注册表信息");
return;
}
CString str;
str.Format("%d",dwValue);
m_strValue=str;
//m_uiValue=dwValue;
UpdateData(FALSE);//更新对话框中内容
regkey.Close();//关闭
}
void CRegRandDlg::OnWrite()
{
CString strPath="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\NonEnum";//注册表子键名
CRegKey regkey;
LONG lResult;
//如果系统中存在该子键,则用Open
//lResult=regkey.Open(HKEY_CURRENT_USER,LPCTSTR(strPath),KEY_ALL_ACCESS);//打开注册表主键
//如果系统中不存在该子键,则用Create
lResult=regkey.Create(HKEY_CURRENT_USER,LPCTSTR(strPath),"REG_DWORD",NULL,KEY_ALL_ACCESS,NULL,NULL);
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法查询有关的注册表信息");
return;
}
UpdateData(TRUE);//更新对话框中内容
int nValue=0;
nValue=atoi(m_strValue);
lResult=regkey.SetValue((DWORD)nValue,LPCTSTR("{20D04FE0-3AEA-1069-A2D8-08002B30309D}"));//写入RegisteredOwner字段
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法设置有关的注册表信息");
return;
}
regkey.Close();
}
void CRegRandDlg::OnShow()
{
CString strPath="Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\NonEnum";//注册表子键名
CRegKey regkey;//注册表类对象
LONG lResult;//返回成功类型
lResult=regkey.Open(HKEY_CURRENT_USER,LPCTSTR(strPath),KEY_ALL_ACCESS);//打开注册表主键
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法打开有关的注册表信息");
return;
}
DWORD dwValue=1;
lResult=regkey.SetValue((DWORD)dwValue,LPCTSTR("{20D04FE0-3AEA-1069-A2D8-08002B30309D}"));//写入RegisteredOwner字段
if (lResult!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法设置有关的注册表信息");
return;
}
regkey.Close();
}
五、编译
六、运行
七、函数说明
SetValue函数声明-----------查阅读写注册表
八、显示隐藏之驱动器
1、点“开始”,点“运行”,输入“regedit”,点“确定”。
2、于注册表编辑器内的子键HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\NonEnum下{20D04FE0-3AEA-1069-A2D8-08002B30309D}项之值修改为“0”,关闭编辑器。
3、重启或注销。隐藏之“我的电脑”显示出来啦。