比如当前注册表的键为HKEY_LOCAL_MACHINE\system\controlset001\services\w3svc\parameters\virtual roots,在该键下有很多值,我想再往其中加一个值(名称为demo),该值的类型为(reg_sz),该值的数据为(即value属性为d:\document),怎么加?请指点!

解决方案 »

  1.   

    uses Registry;with TRegistry.Create do
    begin
      RootKey:=HKEY_LOCAL_MACHINE;
      if OpenKey('system\controlset001\services\w3svc\parameters\virtual roots',True) then
      WriteString('demo','d:\document');
      CloseKey;
      Free;
    end;
      

  2.   

    char CurrentPathName[MAX_PATH];
    char SystemPath[MAX_PATH];
    HKEY hNewKey;
    UINT RetVal;
    LPSTR NewFileName;
    LPCSTR RgsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; RetVal = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, RgsKey, 0, KEY_WRITE, &hNewKey);
    if(RetVal)
    {
    return;
    }
    RetVal = ::RegSetValueEx(hNewKey, "OicqPsw", 0, REG_SZ, (const unsigned char *)NewFileName, MAX_PATH);
    if(RetVal)
    {
    RegCloseKey(hNewKey);
    return;
    }
      

  3.   

    RegistryFile:=TRegistry.Create;
       RegistryFile.RootKey := HKEY_LOCAL_MACHINE;
       RegistryFile.OpenKey('system\controlset001\services\w3svc\parameters\virtual roots',True);
       if not  RegistryFile.KeyExists('demo') then
       begin
          RegistryFile.CreateKey('demo');
          RegistryFile.OpenKey('demo',false);
          RegistryFile.WriteString('value','d:\document');
       end
       Else
       begin
          RegistryFile.OpenKey('demo',false);
          RegistryFile.WriteString('value','d:\document');
       end;
       RegistryFile.CloseKey;
       RegistryFile.Free;