打开与关闭
RegOpenKeyEx RegCloseKey
#include <iostream>
#include <windows.h>
#include<stdlib.h>
using namespace std;
int main()
{
HKEY hkey = NULL;
const TCHAR * subkey = TEXT("Software\\Classes\\ms-settings\\shell\\open\\command");
LONG iret = RegOpenKeyEx(HKEY_CURRENT_USER,subkey,0,KEY_ALL_ACCESS,&hkey);
if(iret == ERROR_SUCCESS)
{
printf("OK");
}
system("pause");
RegCloseKey(hkey);
return 0;
}
创建与删除
#include <iostream>
#include <windows.h>
#include<stdlib.h>
using namespace std;
int main()
{
HKEY hsubkey = NULL;
const TCHAR * subkey = TEXT("Software\\Classes\\ms-settings\\shell\\open\\Mikasa");
LONG iret = RegCreateKeyEx(HKEY_CURRENT_USER,subkey,0,NULL,0,KEY_ALL_ACCESS,NULL,&hsubkey,NULL);
if(iret == ERROR_SUCCESS)
{
printf("OK");
}
system("pause");
return 0;
}
创建成功
删除
#include <iostream>
#include <windows.h>
#include<stdlib.h>
using namespace std;
int main()
{
const TCHAR * subkey = TEXT("Software\\Classes\\ms-settings\\shell\\open\\Mikasa");
LONG iret = RegDeleteKey(HKEY_CURRENT_USER,subkey);
if(iret == ERROR_SUCCESS)
{
printf("OK");
}
system("pause");
return 0;
return 0;
}
对键中的相关操作
设置键值
RegSetValueEx
设置为REG_SZ的值
#include <iostream>
#include <windows.h>
#include <atlstr.h>
#include<stdlib.h>
using namespace std;
int main()
{
HKEY hkey= NULL;
const TCHAR * subkey = TEXT("Software\\Classes\\ms-settings\\shell\\open\\command");
LONG iret = RegOpenKeyEx(HKEY_CURRENT_USER,subkey,0,KEY_ALL_ACCESS,&hkey);
if(iret == ERROR_SUCCESS)
{
CString strPath= TEXT("C:\\Windows\\System32\\cmd.exe");
RegSetValueEx(hkey,TEXT(""),0,REG_SZ,(LPBYTE)strPath.GetBuffer(),strPath.GetLength()*sizeof(TCHAR));
}
else
{
printf("Error");
}
RegCloseKey(hkey);
system("pause");
return 0;
}
设置为DW的值
#include <iostream>
#include <windows.h>
#include <atlstr.h>
#include<stdlib.h>
#pragma comment(lib,"winmm.lib")
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
using namespace std;
int main()
{
HKEY hkey= NULL;
const TCHAR * subkey = TEXT("Software\\Classes\\ms-settings\\shell\\open\\command");
LONG iret = RegOpenKeyEx(HKEY_CURRENT_USER, subkey,0,KEY_ALL_ACCESS,&hkey);
if(iret == ERROR_SUCCESS)
{
DWORD test=0;
CString strPath= TEXT("C:\\Tools\\test.exe");
RegSetValueEx(hkey,TEXT(""),0,REG_SZ,(LPBYTE)strPath.GetBuffer(),strPath.GetLength()*sizeof(TCHAR));
RegSetValueEx(hkey,TEXT("DelegateExecute"),0,REG_DWORD,(BYTE*)&test,sizeof(DWORD));
}
else
{
printf("Error");
}
RegCloseKey(hkey);
return 0;
}
原文链接: https://www.cnblogs.com/Mikasa-Ackerman/p/Cdui-zhu-ce-biao-de-cao-zuo.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/353507
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!