[c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드
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);
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);
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);
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
-
[c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ
-
[c++] MFC 모든 헤더와 라이브러리 설명 | [교류]Programming
-
[c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일
-
[c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드
-
[c++] mfc 간단한 파일 입출력 예제
-
[c++] MD5 구현 소스.. 퍼움..
-
[c++] BHO 프로그램 동작 원리.. 간단하게..
-
[C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】
-
[c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ
-
[c#]뉴 툴바 개인적으로 만든거.. (old)
-
[c#]뉴 툴바 개인적으로 만든거.. (new)
-
[c#] 파일(File) 쓰기 ㅎㅎ
nCount++; 은 필요 없습니다.
RegEnumKey 실행마다 알아서 돕니다.