系統登錄檔儲存操作

2022-08-23 01:33:13 字數 3262 閱讀 3357

1.定義key常量:  下面三個常量可所以定義, 本人是為了程式註冊寫得乙個簡單的這側表訪問功能

const

_rootkey =  hkey_local_machine;

_currentkey = '\software\handy';

_softkeyitem = 'serial_number';

_softcodeid = 'soft_codeid';

_hdid = 'hd_id';

2.具體函式實現

///

/// 讀取 登錄檔字串

///

class function trescommand.findregkeystring(param_rootkey:hkey;param_currentkey,param_keyitem:string):string;

varmyregistry:tregistry;

begin

myregistry:=tregistry.create;

with myregistry do

begin

rootkey:=param_rootkey;

if openkey(param_currentkey,false)=true then

begin

tryresult:=readstring(param_keyitem);

except

result:='';

end;

closekey();

endelse

result:='';

free;

end;

end;

///

///  讀取 登錄檔二進位制

///

class function trescommand.findregkeyinteger(param_rootkey:hkey;param_currentkey,param_keyitem:string):integer;

varmyregistry:tregistry;

begin

myregistry:=tregistry.create;

with myregistry do

begin

rootkey:=param_rootkey;

if openkey(param_currentkey,false)=true then

begin

tryresult:=readinteger(param_keyitem);

except

result:=0;

end;

closekey();

endelse

result:=0;

free;

end;

end;

//寫入

class procedure trescommand.writeregkeyinteger(param_rootkey:hkey;param_currentkey,param_keyitem:string;param_keyinteger:integer);

varmyregistry:tregistry;

begin

myregistry:=tregistry.create;

with myregistry do

begin

rootkey:=param_rootkey;

if openkey(param_currentkey,true)=true then

begin

trywriteinteger(param_keyitem,param_keyinteger);

except

on ex:exception do

msgbox(ex.message,mb_iconstop);

end;

closekey();

endelse

msgbox('沒有找到鍵值!',mb_iconstop);

free;

end;

end;

class procedure trescommand.writeregkeystring(param_rootkey:hkey;param_currentkey,param_keyitem,param_keystring:string);

varmyregistry:tregistry;

begin

myregistry:=tregistry.create;

with myregistry do

begin

rootkey:=param_rootkey;

if openkey(param_currentkey,true)=true then

begin

trywritestring(param_keyitem,param_keystring);

except

on ex:exception do

begin

msgbox(ex.message,mb_iconstop);

end;

end;

closekey();

endelse

msgbox('沒有找到鍵值!',mb_iconstop);

free;

end;

end;

//刪除

class procedure trescommand.deleteregkeyword(param_rootkey:hkey;param_currentkey,param_value:string);

varmyregistry:tregistry;

begin

myregistry:=tregistry.create;

with myregistry do

begin

rootkey:=param_rootkey;

if openkey(param_currentkey,true)=true then

begin

trydeletevalue(param_value); //刪除登錄檔值

deletekey(param_currentkey); //刪除項

closekey;

free;

except

on ex:exception do

msgbox(ex.message,mb_iconstop);

end;

endelse

msgbox('沒有找到鍵值!',mb_iconstop);

free;

end;

end;

登錄檔操作

近來由於需要在自己寫的程式中對登錄檔進行操作。總結些經驗,並做個乙個demo供日後使用,現在把它拿出來和大家分享 小弟初學vc,有誤之處還請賜教。為了使用方便,我把一些操作寫成了函式,以便方便呼叫,具體 如下所示 一 定義 hkey hkey char content 256 所查詢登錄檔鍵值的內容...

登錄檔操作

2005年10月29日 19 29 00 一 寫入 1.建立檔案 建立乙個註冊 式檔案 reg,內容如下 windows registry editor version 5.00 hkey local machine software test server 192.168.66.22 databa...

登錄檔操作

import win32con key win32api.regopenkey win32con.hkey current user,software 0,win32con.key read print key import win32api import win32com key win32api...