-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathRegistryKey.cpp
More file actions
86 lines (77 loc) · 2.49 KB
/
RegistryKey.cpp
File metadata and controls
86 lines (77 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "stdafx.h"
#include "RegistryKey.h"
const TCHAR CMD_LINE_QU_ARG[]=_T(" \"%1\"");
const TCHAR *const szShellRegisterExt[]=
{
_T("dllfile"),
_T("exefile"),
_T("ocxfile"),
_T("scrfile"),
};
void CRegistryKey::RegisterShellExt() const
{
LONG lRes;
HKEY hKey[_countof(szShellRegisterExt)];
for(int i=0;i!=_countof(szShellRegisterExt);++i)
{
CString sName=szShellRegisterExt[i];
sName=sName+_T("\\shell\\")+_T("Unpack with QuickUnpack")+_T("\\command");
lRes=RegCreateKey(HKEY_CLASSES_ROOT,sName.GetBuffer(),&hKey[i]);
if(lRes==ERROR_SUCCESS)
{
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL,szPath,_countof(szPath));
_tcscat_s(szPath,CMD_LINE_QU_ARG);
RegSetValue(hKey[i],NULL,REG_SZ,szPath,(DWORD)_tcslen(szPath)+1);
}
else
return;
}
}
void CRegistryKey::UnRegisterShellExt() const
{
LONG lRes1,lRes2;
for(int i=0;i!=_countof(szShellRegisterExt);++i)
{
CString sName=szShellRegisterExt[i];
sName=sName+_T("\\shell\\")+_T("Unpack with QuickUnpack")+_T("\\command");
lRes1=RegDeleteKey(HKEY_CLASSES_ROOT,sName.GetBuffer());
sName=szShellRegisterExt[i];
sName=sName+_T("\\shell\\")+_T("Unpack with QuickUnpack");
lRes2=RegDeleteKey(HKEY_CLASSES_ROOT,sName.GetBuffer());
if(lRes1!=ERROR_SUCCESS || lRes2!=ERROR_SUCCESS)
return;
}
}
bool CRegistryKey::IsShellRegisterExt() const
{
LONG lRes;
HKEY hKey[_countof(szShellRegisterExt)];
for(int i=0;i!=_countof(szShellRegisterExt);++i)
{
CString name=szShellRegisterExt[i];
name=name+_T("\\shell\\")+_T("Unpack with QuickUnpack");
lRes=RegOpenKeyEx(HKEY_CLASSES_ROOT,name.GetBuffer(),0,KEY_ALL_ACCESS,&hKey[i]);
if(lRes==ERROR_SUCCESS)
RegCloseKey(hKey[i]);
else
return false;
}
return true;
}
void CRegistryKey::RegistryWriteStruct(const TCHAR *szKeyName,const TCHAR *szValueName,void *pStruct,DWORD dwSizeStruct) const
{
TCHAR szIniFile[MAX_PATH]={_T('\0')};
GetModuleFileName(NULL,szIniFile,_countof(szIniFile));
PathToDir(szIniFile);
_tcscat_s(szIniFile,FILE_LOCATION);
WritePrivateProfileStruct(szKeyName,szValueName,pStruct,dwSizeStruct,szIniFile);
}
void CRegistryKey::RegistryReadStruct(const TCHAR *szKeyName,const TCHAR *szValueName,void *pStruct,DWORD dwSizeStruct) const
{
TCHAR szIniFile[MAX_PATH]={_T('\0')};
GetModuleFileName(NULL,szIniFile,_countof(szIniFile));
PathToDir(szIniFile);
_tcscat_s(szIniFile,FILE_LOCATION);
GetPrivateProfileStruct(szKeyName,szValueName,pStruct,dwSizeStruct,szIniFile);
}