天天看點

周遊系統資料庫

 1

周遊系統資料庫

        HKEY regOldHKey;

 2

周遊系統資料庫

 3

周遊系統資料庫

        //Open Register Key

 4

周遊系統資料庫

        if(::RegOpenKeyEx(HKEY_CURRENT_USER,"Software//OKI//CCons33//UNITTYPE",0,KEY_ALL_ACCESS,&regOldHKey)==ERROR_SUCCESS)

 5

周遊系統資料庫
周遊系統資料庫
周遊系統資料庫

{

 6

周遊系統資料庫

            long lResult;

 7

周遊系統資料庫

            DWORD dwIndex=0;

 8

周遊系統資料庫

            CHAR* tcKeyName = new CHAR[MAX_PATH];

 9

周遊系統資料庫

            DWORD dwKeyNameLen = MAX_PATH;

10

周遊系統資料庫

            LPBYTE newByte = new BYTE[MAX_PATH];

11

周遊系統資料庫

            DWORD nType;

12

周遊系統資料庫

            DWORD lpSize=MAX_PATH;

13

周遊系統資料庫

            LPBYTE pbbinKeyData=NULL;

14

周遊系統資料庫

            while(TRUE)

15

周遊系統資料庫
周遊系統資料庫
周遊系統資料庫

{

16

周遊系統資料庫

                //circulate the Register

17

周遊系統資料庫

                lResult=RegEnumValue(regOldHKey,dwIndex,tcKeyName,&dwKeyNameLen,NULL,NULL,NULL,NULL);

18

周遊系統資料庫

                if(lResult!=ERROR_SUCCESS)

19

周遊系統資料庫

                    break; //if the End then break;

20

周遊系統資料庫

21

周遊系統資料庫

                //Use the key Get the value

22

周遊系統資料庫

                long retValue;

23

周遊系統資料庫

                if((retValue=::RegQueryValueEx(regOldHKey,(LPCTSTR)tcKeyName,NULL,&nType,newByte,&lpSize))==ERROR_MORE_DATA)

24

周遊系統資料庫
周遊系統資料庫
周遊系統資料庫

{

25

周遊系統資料庫

                    newByte=(LPBYTE)"NULL";

26

周遊系統資料庫

                }

27

周遊系統資料庫

28

周遊系統資料庫

                //Print the key and the value

29

周遊系統資料庫

                cout<<"Key:"<<(LPCTSTR)tcKeyName;

30

周遊系統資料庫

                cout<<"/t";

31

周遊系統資料庫

                cout<<"Value:"<<(LPCTSTR)newByte<<endl;

32

周遊系統資料庫

                dwIndex++;

33

周遊系統資料庫

                dwKeyNameLen=MAX_PATH;

34

周遊系統資料庫

                lpSize=MAX_PATH;

35

周遊系統資料庫

            }

36

周遊系統資料庫

        }

第二個問題:Link時出錯問題

    在VC中想把系統資料庫删除,查MSDN查到了SHDeleteKey 這個函數,函數使用很簡單:

周遊系統資料庫

if (SHDeleteKey(HKEY_CURRENT_USER, " Software//OKI//CCons32//NeedDelete " ) == ERROR_SUCCESS)

周遊系統資料庫
周遊系統資料庫
周遊系統資料庫

{

周遊系統資料庫

      cout<<"Delete Finish"<<endl;

周遊系統資料庫

   }

      MSDN上面注明要加入shlwapi.h這個頭檔案,但我另進去之後,link出現錯誤. 說是LNK2001無法解析的外部符号“symbol”.

不加,找不到函數定義.

   其實解決這個問題很簡單.在VC菜單中Project->Setting->Link 下面project options的文本框中,輸入shlwapi.lib問題就可以解決了.害得我花了幾個小時時間.

   (或者,在Code前面加上#pragma comment(lib,"shlwapi.lib"))也可以解決問題。

繼續閱讀