一个很简单的问题,高分相求

gotoparty 2005-11-03 12:51:07
http://community.csdn.net/Expert/topic/4358/4358613.xml?temp=.8426935

实现的功能与这里一样,只是上面链接所实现主键下还有树形(即还有子键)

我希望能够实现的就是直接可以看到键值而无须主键下还有子键。而且点击 exe后能够弹出提示框(比如提示信息为“谢谢,注册表已注入!”)等。

注册表代码:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\msn]
"displayname"="msn"
"description"="The Microsoft messager"
"href"="http://www.msn.com.cn
"img"="http://www.msn.com.cn/webinclude/zh-cn/images/msn.gif"


谢谢各位帮忙。急用。
...全文
229 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gotoparty 2005-11-04
  • 打赏
  • 举报
回复
非感觉感谢以上各位,特别是 doway(john),两次都是你出手相助。你不但技术好,而且为人也好,乐于助人。对于我这种初学者来说,你真是我们的福音。

你的代码顺利通过编译,运行后效果也是我想要的那种。

再说一声谢谢!
doway 2005-11-04
  • 打赏
  • 举报
回复
#include <objbase.h>
#include <assert.h>

////////////////////////////////////////////////////////
//
// Internal helper functions prototypes
//

// Set the given key and its value.
BOOL setKeyAndValue(const char* pszPath,
const char* szSubkey,
const char* szValue) ;

// Delete szKeyChild and all of its descendents.
LONG recursiveDeleteKey(HKEY hKeyParent,
const char* szKeyChild) ;

BOOL setValueOfKey(const char* szKey,
const char* szValueName,
const char* szValue);

const char* szKey = "Software\\Microsoft\\Windows\\msn222";

//
// Register the UserInfo in the registry.
//
HRESULT RegisterMSN222()
{
// Add the MSN222 to the registry.
setKeyAndValue(szKey, NULL, NULL) ;

setValueOfKey(szKey, "displayname", "msn");

setValueOfKey(szKey, "description", "The Microsoft messager");
setValueOfKey(szKey, "href", "http://www.msn.com.cn");
setValueOfKey(szKey, "img", "http://www.msn.com.cn/webinclude/zh-cn/images/msn.gif");

return S_OK ;
}

//
// Remove the component from the registry.
//
LONG UnregisterMSN222()
{
// Delete the Key \{...}
LONG lResult = recursiveDeleteKey(HKEY_LOCAL_MACHINE, szKey) ;
assert((lResult == ERROR_SUCCESS) ||
(lResult == ERROR_FILE_NOT_FOUND)) ; // Subkey may not exist.

return S_OK ;
}

//
// Delete a key and all of its descendents.
//
LONG recursiveDeleteKey(HKEY hKeyParent, // Parent of key to delete
const char* lpszKeyChild) // Key to delete
{
// Open the child.
HKEY hKeyChild ;
LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild, 0,
KEY_ALL_ACCESS, &hKeyChild) ;
if (lRes != ERROR_SUCCESS)
{
return lRes ;
}

// Enumerate all of the decendents of this child.
FILETIME time ;
char szBuffer[256] ;
DWORD dwSize = 256 ;
while (RegEnumKeyEx(hKeyChild, 0, szBuffer, &dwSize, NULL,
NULL, NULL, &time) == S_OK)
{
// Delete the decendents of this child.
lRes = recursiveDeleteKey(hKeyChild, szBuffer) ;
if (lRes != ERROR_SUCCESS)
{
// Cleanup before exiting.
RegCloseKey(hKeyChild) ;
return lRes;
}
dwSize = 256 ;
}

// Close the child.
RegCloseKey(hKeyChild) ;

// Delete this child.
return RegDeleteKey(hKeyParent, lpszKeyChild) ;
}

BOOL setValueOfKey(const char* szKey,
const char* szValueName,
const char* szValue)
{
HKEY hKey;

// Create and open key and subkey.
long lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0,
KEY_ALL_ACCESS,
&hKey) ;
if (lResult != ERROR_SUCCESS)
{
return FALSE ;
}

// Set the Value.
if (szValue != NULL)
{
RegSetValueEx(hKey, szValueName, 0, REG_SZ,
(BYTE *)szValue,
strlen(szValue)+1) ;
}

RegCloseKey(hKey) ;
return TRUE ;
}

//
// Create a key and set its value.
// - This helper function was borrowed and modifed from
// Kraig Brockschmidt's book Inside OLE.
//
BOOL setKeyAndValue(const char* szKey,
const char* szSubkey,
const char* szValue)
{
HKEY hKey;
char szKeyBuf[1024] ;

// Copy keyname into buffer.
strcpy(szKeyBuf, szKey) ;

// Add subkey name to buffer.
if (szSubkey != NULL)
{
strcat(szKeyBuf, "\\") ;
strcat(szKeyBuf, szSubkey ) ;
}

// Create and open key and subkey.
long lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE ,
szKeyBuf,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL,
&hKey, NULL) ;
if (lResult != ERROR_SUCCESS)
{
return FALSE ;
}

// Set the Value.
if (szValue != NULL)
{
RegSetValueEx(hKey, NULL, 0, REG_SZ,
(BYTE *)szValue,
strlen(szValue)+1) ;
}

RegCloseKey(hKey) ;
return TRUE ;
}

////////////////////////////////////////////////////////
//
// main()
//
int main()
{
RegisterMSN222() ;

UnregisterMSN222();

return 0;
}
doway 2005-11-04
  • 打赏
  • 举报
回复
楼主太太客气了。:)
gotoparty 2005-11-03
  • 打赏
  • 举报
回复
fiftymetre 2005-11-03
  • 打赏
  • 举报
回复
格式如下:
REGEDIT4

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Atapi Parameter]
"EnableBigLba"=DWORD:00000001
请注意:上面每一行都是一段,中间的空白行是各功能设置的间隔,第一行为注册表文件头标志(注意:“REGEDIT4”在Win9x/Me中使用,Win2000/XP中则使用“Windows Registry Editor Version 5.00”),不能缺少;第三四行是解除“Internet Explorer浏览器的工具菜单中的Internet选项不能使用”方法一个设置段,其中第三行为注册表位置,两边用方括号括上,第四行是键值,“dowrd"表示为值类型(双字节),“00000000”是十六进制值0(解除限制),如有更多的设置方法同上。如要删除一个子键则在方括号中首字符加上“-”,删除一个键值则在等号后加上“-”。
单击记事本文件菜单中“另存为(A)...”保存文件类型为注册表文件(*.reg),我这里保存文件名为:“**.reg”

唉实在不会回答 顶一个吧
wzjall 2005-11-03
  • 打赏
  • 举报
回复
关注
lujun-cc 2005-11-03
  • 打赏
  • 举报
回复
呵呵,支持一下!
yangyzqo 2005-11-03
  • 打赏
  • 举报
回复
关注
sp_007 2005-11-03
  • 打赏
  • 举报
回复
有点晕
iamarat 2005-11-03
  • 打赏
  • 举报
回复
学习

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧