CRegKey reg;
if(reg.Open(HKEY_LOCAL_MACHINE,"System\\CurrentControlSet\\Control\\Session Manager\\Environment\\")==ERROR_SUCCESS) // 路径自定
{
TCHAR path[MAX_PATH];
DWORD dw = MAX_PATH;
if(ERROR_SUCCESS==reg.QueryValue(path,"path",&dw))
{
MessageBox(path,"找到Path了");
CString AltPath = path;
CString str;
//长度
str.Format("%d",AltPath.GetLength());
MessageBox(str);
//显示字符的位置
str.Format("%d",AltPath.Find("需要的字符串;",1));
MessageBox(str);
//删除原来的字符串
AltPath.Delete(AltPath.Find("字符串;",1),13);
MessageBox(AltPath);
//添加新路径
AltPath.Insert(AltPath.GetLength(),"添加的新字符串;");
reg.SetValue(HKEY_LOCAL_MACHINE,"System\\CurrentControlSet\\Control\\Session Manager\\Environment\\path",AltPath,"");
reg.SetValue(AltPath,"path");
reg.QueryValue(path,"path",&dw);
MessageBox(path);
reg.Close();
}
}
else
{
MessageBox("lalal");
//注册表键值不存在
MessageBox("Path Not Found!");
}
posted on 2006-09-28 08:51
小歪 阅读(1304)
评论(0) 编辑 收藏 引用