C 登錄檔操作大全

2021-05-17 23:33:58 字數 3609 閱讀 6236

1.開啟鍵

//using microsoft.win32;

registrykey rklocalm = registry.localmachine; //registry.classesroot, registry.localmachine, registry.users, registry.currentconfig

const string strsubkey = %%1; //@"software/odbc/odbc.ini/dbnewtest/test"

registrykey rksub = rklocalm.opensubkey( strsubkey );

//rklocalm = registry.localmachine; //registry.classesroot, registry.localmachine, registry.users, registry.currentconfig

//rklocalm.opensubkey(%%1);

2.新增鍵

//using microsoft.win32;

registrykey rklocalm = registry.localmachine; //registry.classesroot, registry.localmachine, registry.users, registry.currentconfig

const string strsubkey = %%1; //@"software/odbc/odbc.ini/dbnewtest/test"

registrykey rksub = rklocalm.createsubkey( strsubkey );

rklocalm.close();

3.刪除鍵

rksub.deletesubkey( %%1, false );

4.列舉第乙個鍵

//using system.collections;

ienumeratorit = subkey.getsubkeynames().first();

string %%1=it.current;

5.列舉下乙個鍵

string %%1=null;

if(it.movenext());

%%1=it.current;

6.獲取dword值

%%2=rksub.getvalue(%%1);

7.獲取二進位制值

%%2=rksub.getvalue(%%1);

8.讀取字串值

%%2=rksub.getvalue(%%1);

9.寫入字串值

rksub.setvalue( %%1, "test" );

10.寫入二進位制值

rksub.setvalue(%%1, value, registryvaluekind.binary);

11.寫入dword值

rksub.setvalue(%%1, value, registryvaluekind.dword);

12.設定dword值

rksub.add(%%1, value, registryvaluekind.dword);

13.刪除值

rksub.deletevalue( %%1, false );//"driverid"

14.關閉鍵

rksub.close();

15.列出乙個鍵下所有的子鍵

string strsubkeys = rksub.getsubkeynames();

for( int i = 0; i < strsubkeys.length; i++ )

16.列出乙個鍵下所有的值

string strdata = rksub.getvaluenames();

for( int i = 0; i < strdata.length; i++ )

:", strdata[i], rksub.getvalue( strdata[i] ) ) );

}17.列出乙個鍵下所有的子鍵和值

string strsubkeys = rksub.getsubkeynames();

for( int i = 0; i < strsubkeys.length; i++ )

string strdata = rksub.getvaluenames();

for( int i = 0; i < strdata.length; i++ )

:", strdata[i], rksub.getvalue( strdata[i] ) ) );

}18.列舉所有的子鍵和值

//using microsoft.win32;

private static void access_registry(registrykey keyr, string str)

string value = aimdir.getvalue(valuename) as string;

if (value != null)}}

subkeynames = aimdir.getsubkeynames();

foreach (string keyname in subkeynames)

access_registry(aimdir, keyname);}}

catch (exception)

}registrykey keys =;

foreach (registrykey key in keys)

key.close();

}19.模糊搜尋所有的子鍵和值,查詢特定字串並刪除

//using system.collections;using microsoft.win32;

registrykey keys =;// registry.classesroot, registry.currentconfig

foreach (registrykey key in keys)

else}}

}subkeynames = aimdir.getsubkeynames();

foreach (string keyname in subkeynames)

al.enqueue(keyname);

qu.enqueue(aimdir);}}

catch (exception)

}key.close();

}20.清空乙個子鍵

//using microsoft.win32;

registrykey rklocalm = registry.localmachine; //registry.classesroot, registry.localmachine, registry.users, registry.currentconfig

const string strsubkey = %%1; //@"software/odbc/odbc.ini"

registrykey rksub = rklocalm.opensubkey( strsubkey, true );

rksub.deletesubkeytree(%%2); //"dbnewtest"

rklocalm.close();

registrykey rksub = rklocalm.createsubkey( strsubkey +"/"+%%2);

rklocalm.close();

c 操作登錄檔

1.讀取指定名稱的登錄檔的值 private string getregistdata string name 以上是讀取的登錄檔中hkey local machine software目錄下的 目錄中名稱為name的登錄檔值 2.向登錄檔中寫資料 private void wtregedit st...

C 登錄檔操作

寫這篇日誌以前不是沒有接觸過c 來操作登錄檔,但這次的體會更深入了一點,故筆記如下。首先可以從 登錄檔reg檔案語法規則 了解下.reg檔案的語法規則,因為很多時候是把.reg裡的 轉換為程式裡的啊。知道語法後,可以根據裡面的 開始逐個轉化為c 了。首先是建立hkey,呼叫regcreatekey或...

C 操作登錄檔

windows 作業系統的登錄檔包含了很多有關計算機執行的配置方式,開啟登錄檔我們可以看到登錄檔是按類似於目錄的樹結構組織的,其中第二級目錄包含了五個預定義主鍵分別是 hkey classes root,hkey current user,hkey local machine,hkey users,...