用戶: 密碼:     忘記密碼 | 會員註冊
  

C++builder編程修改註冊表的問題

8.8
出處:2345軟件大全 時間:2011-06-27 人氣:764

核心提示:RootKey是註冊表的根鍵值,比如運行regedit後看到的HKEY_USERS,HKEY_LOCAL_MACHINE就是RootKey,在TRegIniFile中缺省的RootKey是HKEY_USERS

  RootKey是註冊表的根鍵值,比如運行regedit後看到的HKEY_USERS,HKEY_LOCAL_MACHINE就是RootKey,在TRegIniFile中缺省的RootKey是HKEY_USERS.

下面的例子是TRegistry的,TRegIniFile也差不多
void __fastcall TfrmMainForm::WriteToMyRegistry(int table_count)
{
//TODO: Add your source code here
TRegistry *MyRegistry=new TRegistry;
MyRegistry->RootKey=HKEY_LOCAL_MACHINE;  //改變缺省Rootkey
if(!MyRegistry->OpenKey("Software\Microsoft\Windows\CurrentVersion\Run",true)) //打開主鍵
//這樣雙引號裡面的東西就變成了CurrentKey
{
Application->MessageBox("註冊表內容無效", "讀取註冊表出錯",MB_ICONERROR);
MyRegistry->CloseKey();
delete MyRegistry;
return;
}
MyRegistry->WriteString("myrun","c:\sthvcd\sthvcd.exe");
MyRegistry->CloseKey();
delete MyRegistry;