Contents

조회 수 15336 댓글 2
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
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;
}



?
  • ?
    kyle 2015.09.14 19:23
    4. 서브 키까지 삭제 (recursive) 에서
    nCount++; 은 필요 없습니다.
    RegEnumKey 실행마다 알아서 돕니다.
  • profile
    hooni 2015.09.15 20:01

    댓글 감사합니다.
    근데, 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


List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
897 Database [mysql] CPU 점유율이 높을 때 확인할 내용 hooni 2015.08.26 6651
896 System/OS [ms-sql] 프로시져 예제.. file hooni 2013.04.23 13406
895 System/OS [ms-sql] 서브스트링(substring), 프로시저(SP) 작성 예제 hooni 2013.04.23 41297
894 Develop [maven] Mac OS에 메이븐(maven) 설치하기 file hooni 2015.01.21 1112
893 Develop [matlab] 정보은닉 스테가노그래피(Steganography) 수업 file hooni 2016.10.03 686
892 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 1994
891 System/OS [mac][추천 무료앱] 구름 입력기 - 국내 맥 사용자를 위한 한글 대안 입력기 1 file hooni 2015.01.04 2165
890 System/OS [mac] 패키지 매니저, MacPort hooni 2015.01.03 978
889 System/OS [mac] 컨텍스트(Context) 메뉴 "다음으로 열기" 내용 정리 hooni 2013.07.10 18798
888 System/OS [mac] 맥에서 슬립(잠자기) 모드 진입을 막는 방법~ hooni 2013.10.10 30888
887 System/OS [mac] 맥에서 기본 실행 앱 변경하기 file hooni 2018.03.02 1815
886 System/OS [mac] 맥에서 APM(apache,php,mysql) 구성하기 hooni 2013.04.23 38619
Board Pagination Prev 1 ... 19 20 21 22 23 24 25 26 27 28 ... 98 Next
/ 98