본문 바로가기

Programming/Windows&C#

[Windows/WinAPI] 레지스트리 Key 생성하기(실습4)

728x90
반응형

#include <Windows.h>

#include <tchar.h>

#include <locale.h>

#include <stdio.h>


int _tmain(INT argv , LPTSTR argc[])

{

LONG result = 0;

LONG result2 = 0;

TCHAR data1[20];

TCHAR data2[50];

DWORD data3 ;


HKEY obtainKey = NULL;


_tsetlocale(LC_ALL, _T("Korean"));

_tprintf(_T("2010105094 정민우\n"));

if(argv != 4)

{

_tprintf(_T("error\n"));

return 1;

}

_tcscpy(data1 ,argc[2]);

_tcscpy(data2 ,argc[1]);

data3 = (DWORD)_ttoi(argc[3]);

if(_tcscmp(data2, _T("HKEY_CURRENT_USER")) == 0)

{

result = RegCreateKeyEx(HKEY_CURRENT_USER , (LPTSTR)data1,0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE,

NULL , &obtainKey, NULL);

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegCreateKeyEx error3_1"));

return 3;

}

}

else if(_tcscmp(data2, _T("HKEY_LOCAL_MACHINE")) == 0)

{

result = RegCreateKeyEx(HKEY_LOCAL_MACHINE , (LPTSTR)data1,0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE,

NULL , &obtainKey, NULL);

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegCreateKeyEx error3_2"));

return 3;

}

}

else if(_tcscmp(data2, _T("HKEY_USERS")) == 0)

{

result = RegCreateKeyEx(HKEY_USERS , (LPTSTR)data1,0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE,

NULL , &obtainKey, NULL);

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegCreateKeyEx error3_3"));

return 3;

}

}

else if(_tcscmp(data2, _T("HKEY_CURRENT_CONFIG")) == 0)

{

result = RegCreateKeyEx(HKEY_CURRENT_USER , (LPTSTR)data1,0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE,

NULL , &obtainKey, NULL);

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegCreateKeyEx error3_4"));

return 3;

}

}

else if(_tcscmp(data2, _T("HKEY_CLASSES_ROOT")) == 0)

{

result = RegCreateKeyEx(HKEY_CLASSES_ROOT , (LPTSTR)data1,0 , NULL , REG_OPTION_NON_VOLATILE, KEY_WRITE,

NULL , &obtainKey, NULL);

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegCreateKeyEx error3_5"));

return 3;

}

}

else

{

_tprintf(_T("error2"));

return 2;

}



result2 = RegSetValueEx(obtainKey , NULL, 0 , REG_DWORD, (BYTE*)&data3 , sizeof(data3));

if(result != ERROR_SUCCESS)

{

_tprintf(_T("RegSetValueEx error2"));

return 4;

}

return 0;

}


// argc[0] : 응용프로그램 이름

// argc[1] : 레지스트리 위치에 대한 정보가 들어간다.

// argc[2] : 키값을 생성할 폴더 & 경로에 대한 값이 들어간다.

// atgc[3] : 키값으로 들어갈 DWORD 값을 입력 받는다.

// "RegCreateKeyEx" 해당 레지스트리 경로에 키값을 생성한다.

// "RegCreateKeyEx"가 성공하면 웃기게도 ERROR_SUCCESS를 반환한다.

// "RegSetValueEx"함수는 지정 경로에다가 Key에다가 데이터값을 생성하는 함수이다.



2010105094_정민우.cpp




반응형