Develop
2013.04.23 15:43
[c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드
조회 수 15332 댓글 2
1. 레지스트리 추가
레지스트리 추가 부분에서는 위에 루트에..
abc라는 이름과 "c:winntsystem32
otepad.exe"의 데이터를 갖는것을 추가하는 예제 코드.
LONG lResult; char buffer[100]; HKEY hKey; DWORD dwDesc; char *path = "c:winntsystem32 otepad.exe"; // 노트 패드 경로 // 레지스트리 열고 RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftWindowsCurrentVersionRun", 0, KEY_ALL_ACCESS, &hKey); // Set Registry Key & Value lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftWindowsCurrentVersionRun", 0, buffer, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDesc); if(lResult == ERROR_SUCCESS) { RegSetValueEx(hKey, "abc", 0, REG_SZ, (BYTE*)path, strlen(path)); } //레지스트리 닫고 RegCloseKey(hKey);
2. 레지스트리 삭제
LONG lResult; HKEY hKey; DWORD dwBytes=100; CString str = "abc"; // open Regstry Key lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftWindowsCurrentVersionRun", 0, KEY_ALL_ACCESS, &hKey); if(lResult != ERROR_SUCCESS) { AfxMessageBox("Register Open Error"); } lResult = RegDeleteValue(hKey, str); // 삭제 if (lResult == ERROR_SUCCESS) AfxMessageBox("레지스터 삭제 성공"); else AfxMessageBox("실패당...ㅠㅠ"); RegCloseKey(hKey);
3. 레지스트리 읽기
LONG lResult; HKEY hKey; DWORD dwType; DWORD dwBytes=100; char buffer[100]; // open Regstry Key lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWAREMicrosoftWindowsCurrentVersionRun", 0, KEY_ALL_ACCESS, &hKey); if(lResult != ERROR_SUCCESS) { AfxMessageBox("Register Open Error"); } // Read Regstry Key lResult=RegQueryValueEx(hKey, "abc", 0, &dwType, (LPBYTE)buffer, &dwBytes); if(lResult == ERROR_SUCCESS) AfxMessageBox(buffer); else AfxMessageBox("Register Read Error"); RegCloseKey(hKey);
4. 서브 키까지 삭제 (recursive)
void SimpleApp::DeleteRegKey() { HKEY m_hKey = NULL; char svSubKeyBuf[MAX_PATH+1]; long m_RetValue = ::RegOpenKeyEx(HKEY_CURRENT_USER, "SoftwareTest",0,KEY_ALL_ACCESS,&m_hKey); if(m_RetValue == ERROR_SUCCESS) // 오픈 성공하면... { RegDeleteKeyRecurse( HKEY_CURRENT_USER, _T("SoftwareTest"), svSubKeyBuf); } return; } int SimpleApp::RegDeleteKeyRecurse(HKEY hKey, LPCTSTR lpSubKey, char *svKeyBuf) { int nCount=0; char svSubKeyBuf[MAX_PATH+1]; HKEY hSubKey; if(RegOpenKeyEx(hKey,lpSubKey,0,KEY_ALL_ACCESS,&hSubKey) !=ERROR_SUCCESS) { return -1; } while(RegEnumKey(hSubKey,nCount,svKeyBuf,MAX_PATH) !=ERROR_NO_MORE_ITEMS) { if(RegDeleteKeyRecurse(hSubKey,svKeyBuf,svSubKeyBuf)==-1) { RegCloseKey(hSubKey); return 1; } nCount++; } RegCloseKey(hSubKey); RegDeleteKey(hKey,lpSubKey); return 0; }
- ?
-
댓글 감사합니다.
근데, nCount가 포인터도 아니고 해서 RegEnumKey 에서 증가시킬 방법이 없을텐데요.
그리고 MSDN에 보면 프로그램에서 증가시키라고 나와있습니다.RegEnumKey(hKey, dwIndex, lpName, cchName);
The application should then increment the dwIndex parameter...[참고] https://msdn.microsoft.com/en-us/us/windows/apps/ms724861
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
897 | Develop | [js] 간단한 게임 프로토타입 (HTML5 와는 무관) | hooni | 2013.04.23 | 15152 |
896 | Etc | 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ | hooni | 2013.06.17 | 15121 |
895 | Algorithm | [algorithm] Greedy (탐욕 기법) | hooni | 2003.04.23 | 15108 |
894 | Develop | [c] GD라이브러리(jpeg)를 사용한 웹 카운터 샘플 | hooni | 2013.04.23 | 15107 |
893 | Database | [sql] 간단한 통계 서브쿼리 예제.. | hooni | 2013.04.23 | 15088 |
892 | System/OS | [linux] 아파치설치/설정 - 사용인증 | hooni | 2003.04.23 | 15085 |
891 | System/OS | [perl] 펄 환경 설정해야 할거 ㅋㅋ | hooni | 2003.04.23 | 14992 |
890 | Develop | [c++][mfc] 파일 입출력 샘플 (한줄씩 읽어서 다른 파일에 쓰기) | hooni | 2013.04.23 | 14983 |
889 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 14949 |
888 | System/OS | [linux] 이기종간의 파일 공유(Samba) | hooni | 2003.04.23 | 14900 |
887 | System/OS | [linux] 웹로그분석기(webalizer) 설치 & 팁 | hooni | 2003.04.23 | 14882 |
886 | Develop | [ios] UIWebView에서 NSURLRequest에 Cookie 실어 보내기 | hooni | 2014.01.16 | 14859 |
nCount++; 은 필요 없습니다.
RegEnumKey 실행마다 알아서 돕니다.