在win2000的註冊表中有一種類型爲REG_MULTI_SZ,如:
---------------------------
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\TlntSvr]
"DependOnService"=hex(7):52,00,70,00,63,00,53,00,73,00,00,00,54,00,63,00,70,00, 49,00,70,00,00,00,00,00
"Deforbiddenion"="允許遠端用戶登錄到系統並且使用命令行運行控制臺程式。"
---------------------------
上面的DependOnService就是REG_MULTI_SZ類型。
這種類型在註冊表裏無法建立,請問各位老大:在delphi中如何修改REG_MULTI_SZ類型的值?
(這種類型可以用ReadBinaryData來讀取。)
謝謝!
上面這篇文章中提供解法,我把它貼上來。希望對你有幫助。
See if this is what you are after;
uses registry; ...
procedure kg_ReadStrings(const valueName: string; aStrings: TStrings; oReg:TRegistry) ; var valueType : DWORD ; valueLen : DWORD ; p, buffer : PChar ; begin aStrings.Clear ; SetLastError(RegQueryValueEx(oReg.CurrentKey, PChar(valueName),nil, @valueType,nil, @valueLen)) ; if GetLastError = ERROR_SUCCESS then if valueType = REG_MULTI_SZ then begin GetMem(buffer, valueLen) ; try RegQueryValueEx(oReg.CurrentKey, PChar(valueName), nil, nil, PBYTE(buffer), @valueLen) ; p := buffer ; while p^ <> #0 do begin aStrings.Add(p) ; Inc(p, lstrlen(p) + 1) end finally FreeMem(buffer) end end else raise ERegistryException.Create('String list expected') else raise Exception.Create('Unable read MULTI_SZ value') end;
procedure kg_WriteStrings(const valueName: string; aStrings: TStrings; oReg:TRegistry) ; var p, buffer : PChar ; i : Integer ; size : DWORD ; begin size := 0 ; for i := 0 to aStrings.Count - 1 do Inc(size, Length(aStrings [i]) + 1) ; Inc (size) ; GetMem(buffer, size) ; try p := buffer ; for i := 0 to aStrings.count - 1 do begin lstrcpy(p, PChar(aStrings [i])) ; Inc(p, lstrlen (p) + 1) end; p^ := #0 ; SetLastError(RegSetValueEx(oReg.CurrentKey, PChar(valueName), 0, REG_MULTI_SZ, buffer, size)) ; if GetLastError <> ERROR_SUCCESS then raise Exception.Create('Unable to write MULTI_SZ value') ; finally FreeMem(buffer) end end;
... var Reg : TRegistry ; aStr: TStringList ; begin Reg := TRegistry.Create ; aStr:= TStringList.Create ;
try if Reg.OpenKey('kg_ms',True) then begin aStr.Add('This is a test to see how to read and write') ; aStr.Add('MULTI_SZ type to the system registry.') ; aStr.Add('Infomation entered: ' + DateToStr(Date)) ; kg_WriteStrings('m1',aStr,Reg) ; Reg.CloseKey ; end ; finally Reg.Free ; aStr.Free ; end ;
...
Reg := TRegistry.Create ; aStr:= TStringList.Create ; try if Reg.OpenKey('kg_ms',False) then begin kg_ReadStrings('m1',aStr,Reg) ; Reg.CloseKey ;
{ Clean up our mess by removing the key and value we created } Reg.DeleteValue('m1') ; Reg.DeleteKey('kg_ms') ;
if aStr.Count >0 then {ListBox1.Items.Assign(aStr)} else {ListBox1.Items.Add('Operation failed') ;} end ; finally Reg.Free ; aStr.Free ; end ;
|
阅读(3191) | 评论(0) | 转发(0) |