注册表问题-----如何建立删除主键和子键?

时间:2021-12-21 05:19:46
如何在根键HKEY_LOCAL_MACHINE先建立主键MyKey在该主键下建立MySetUp子键,
在子键中写入字符串"My God I come"

如何依次从后往前删除字符串,子键,主键?

7 个解决方案

#1


HKEY hKey;
HKEY hSubKey1;
HKEY hSubKey2;

if(ERROR_SUCCESS!=RegOpenKeyEx(HKEY_LOCAL_MACHINE,NULL,0,KEY_WRITE,hKey))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegCreateKeyEx(hKey,"MyKey",0,NULL,REG_OPTION_VOLATILE,KEY_WRITE,lpSecurityAt,hSubKey1,REG_CREATED_NEW_KEY))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegCreateKeyEx(hSubKey1,"MySetUp",0,NULL,REG_OPTION_VOLATILE,KEY_WRITE,lpSecurityAt,hSubKey2,REG_CREATED_NEW_KEY))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegSetValue(hSubKey1,"MySetUp",REG_SZ,"My God I come",length("My God I come")))
{
    exit(0);  //error
}
大概是这样,详细的用法查查MSDN。
删除是要先打开吧。

#2


我来关注一下吧
我知道写的话可以用
AfxGetApp()->WriteProfileString(,,);
AfxGetApp()->WriteProfileInt(,,);

#3


一个实用的注册表类


在日常编程中,注册表的使用非常广泛,为此,笔者仔细研究了关于注册表的API函数(全部在WINREG.H中定义),编写了这个注册表类class CRegistry,供大家参考。 主要函数介绍如下: 

1、 CreateKey(LPCTSTR lpSubKey) 
创建指定键。 
CreateKey("Staff\0"); 

2、 Open(LPCTSTR lpSubKey)
打开指定键。 
Open( "Software\\Staff\0"); 

3、 Read(LPCTSTR lpValueName, Cstring* lpVal); 
Read(LPCTSTR lpValueName, DWORD* pdwVal); 
Read(LPCTSTR lpValueName, int* pnVal); 
读指定键值内容。 

4、Write(LPCTSTR lpSubKey, LPCTSTR lpVal); 
Write(LPCTSTR lpSubKey, DWORD dwVal); 
Write(LPCTSTR lpSubKey, int nVal); 
将内容写入指定键。 

5、 DeleteKey(HKEY hKey, LPCTSTR lpSubKey); 
删除指定键。 
DeleteKey(HKEY_LOCAL_MACHINE,"staff\0"); 
DeleteKey(m_hKey,"name\0"); 

6、 DeleteValue(LPCTSTR lpValueName); 
从指定键删除指定的值。 
DeleteKey("name");

7、SaveKey(LPCTSTR lpFileName); 
将指定键、子键及值存入文件。 
SaveKey("save.reg"); 

8、 RestoreKey(LPCTSTR lpFileName); 
从指定文件读取注册表信息。 
RestoreKey("save.reg");

9、 Close(); 释放指定键的句柄

#4


来晚了,就下面几个了
RegOpenKeyEx
RegCreateKeyEx
RegSetValue

#5


请诸位写几行,RegOpenKeyEx  RegCreateKeyEx   RegSetValue函数我有,就是个参数含义和取值不清,MSDN上也没有例子!!!!!!

#6


HKEY key1,key2,key3;
  DWORD d=sizeof(char);
      if (ERROR_SUCCESS==RegOpenKeyEx(HKEY_CURRENT_USER,"",0,KEY_READ,&key1   {
 
     if (HKEY_LOCAL_MACHINE==RegCreateKeyEx(key1,"MyKey",0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&key2,&d))
 { MessageBox("open");

if (ERROR_SUCCESS==RegCreateKeyEx(key2,"MySetup",0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&key3,&d))
{


RegSetValueEx(key3,NULL,NULL,REG_SZ,(LPBYTE)"My God I come",MAX_PATH);
RegCloseKey(key3);

}

RegCloseKey(key2);
}

RegCloseKey(key1);
}

看看你的HKEY_CURRENT_USER有没有写进去了!

#7


就是没办法对HKEY_LOCAL_MACHINE进行操作

#1


HKEY hKey;
HKEY hSubKey1;
HKEY hSubKey2;

if(ERROR_SUCCESS!=RegOpenKeyEx(HKEY_LOCAL_MACHINE,NULL,0,KEY_WRITE,hKey))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegCreateKeyEx(hKey,"MyKey",0,NULL,REG_OPTION_VOLATILE,KEY_WRITE,lpSecurityAt,hSubKey1,REG_CREATED_NEW_KEY))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegCreateKeyEx(hSubKey1,"MySetUp",0,NULL,REG_OPTION_VOLATILE,KEY_WRITE,lpSecurityAt,hSubKey2,REG_CREATED_NEW_KEY))
{
    exit(0);  //error
}
if(ERROR_SUCCESS!=RegSetValue(hSubKey1,"MySetUp",REG_SZ,"My God I come",length("My God I come")))
{
    exit(0);  //error
}
大概是这样,详细的用法查查MSDN。
删除是要先打开吧。

#2


我来关注一下吧
我知道写的话可以用
AfxGetApp()->WriteProfileString(,,);
AfxGetApp()->WriteProfileInt(,,);

#3


一个实用的注册表类


在日常编程中,注册表的使用非常广泛,为此,笔者仔细研究了关于注册表的API函数(全部在WINREG.H中定义),编写了这个注册表类class CRegistry,供大家参考。 主要函数介绍如下: 

1、 CreateKey(LPCTSTR lpSubKey) 
创建指定键。 
CreateKey("Staff\0"); 

2、 Open(LPCTSTR lpSubKey)
打开指定键。 
Open( "Software\\Staff\0"); 

3、 Read(LPCTSTR lpValueName, Cstring* lpVal); 
Read(LPCTSTR lpValueName, DWORD* pdwVal); 
Read(LPCTSTR lpValueName, int* pnVal); 
读指定键值内容。 

4、Write(LPCTSTR lpSubKey, LPCTSTR lpVal); 
Write(LPCTSTR lpSubKey, DWORD dwVal); 
Write(LPCTSTR lpSubKey, int nVal); 
将内容写入指定键。 

5、 DeleteKey(HKEY hKey, LPCTSTR lpSubKey); 
删除指定键。 
DeleteKey(HKEY_LOCAL_MACHINE,"staff\0"); 
DeleteKey(m_hKey,"name\0"); 

6、 DeleteValue(LPCTSTR lpValueName); 
从指定键删除指定的值。 
DeleteKey("name");

7、SaveKey(LPCTSTR lpFileName); 
将指定键、子键及值存入文件。 
SaveKey("save.reg"); 

8、 RestoreKey(LPCTSTR lpFileName); 
从指定文件读取注册表信息。 
RestoreKey("save.reg");

9、 Close(); 释放指定键的句柄

#4


来晚了,就下面几个了
RegOpenKeyEx
RegCreateKeyEx
RegSetValue

#5


请诸位写几行,RegOpenKeyEx  RegCreateKeyEx   RegSetValue函数我有,就是个参数含义和取值不清,MSDN上也没有例子!!!!!!

#6


HKEY key1,key2,key3;
  DWORD d=sizeof(char);
      if (ERROR_SUCCESS==RegOpenKeyEx(HKEY_CURRENT_USER,"",0,KEY_READ,&key1   {
 
     if (HKEY_LOCAL_MACHINE==RegCreateKeyEx(key1,"MyKey",0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&key2,&d))
 { MessageBox("open");

if (ERROR_SUCCESS==RegCreateKeyEx(key2,"MySetup",0,0,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&key3,&d))
{


RegSetValueEx(key3,NULL,NULL,REG_SZ,(LPBYTE)"My God I come",MAX_PATH);
RegCloseKey(key3);

}

RegCloseKey(key2);
}

RegCloseKey(key1);
}

看看你的HKEY_CURRENT_USER有没有写进去了!

#7


就是没办法对HKEY_LOCAL_MACHINE进行操作