本文整理汇总了C++中RegCloseKey函数的典型用法代码示例。如果您正苦于以下问题:C++ RegCloseKey函数的具体用法?C++ RegCloseKey怎么用?C++ RegCloseKey使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegCloseKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: register_decoders
/***********************************************************************
* register_decoders
*/
static HRESULT register_decoders(struct regsvr_decoder const *list)
{
LONG res = ERROR_SUCCESS;
HKEY coclass_key;
WCHAR buf[39];
HKEY decoders_key;
HKEY instance_key;
res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
if (res == ERROR_SUCCESS) {
StringFromGUID2(&CATID_WICBitmapDecoders, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &decoders_key, NULL);
if (res == ERROR_SUCCESS)
{
res = RegCreateKeyExW(decoders_key, instance_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_coclass_key;
}
if (res != ERROR_SUCCESS)
RegCloseKey(coclass_key);
}
if (res != ERROR_SUCCESS) goto error_return;
for (; res == ERROR_SUCCESS && list->clsid; ++list) {
HKEY clsid_key;
HKEY instance_clsid_key;
StringFromGUID2(list->clsid, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_coclass_key;
StringFromGUID2(list->clsid, buf, 39);
res = RegCreateKeyExW(instance_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &instance_clsid_key, NULL);
if (res == ERROR_SUCCESS) {
res = RegSetValueExW(instance_clsid_key, clsid_valuename, 0, REG_SZ,
(CONST BYTE*)(buf), 78);
RegCloseKey(instance_clsid_key);
}
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
if (list->author) {
res = RegSetValueExA(clsid_key, author_valuename, 0, REG_SZ,
(CONST BYTE*)(list->author),
strlen(list->author) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->friendlyname) {
res = RegSetValueExA(clsid_key, friendlyname_valuename, 0, REG_SZ,
(CONST BYTE*)(list->friendlyname),
strlen(list->friendlyname) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->vendor) {
StringFromGUID2(list->vendor, buf, 39);
res = RegSetValueExW(clsid_key, vendor_valuename, 0, REG_SZ,
(CONST BYTE*)(buf), 78);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->version) {
res = RegSetValueExA(clsid_key, version_valuename, 0, REG_SZ,
(CONST BYTE*)(list->version),
strlen(list->version) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->mimetypes) {
res = RegSetValueExA(clsid_key, mimetypes_valuename, 0, REG_SZ,
(CONST BYTE*)(list->mimetypes),
strlen(list->mimetypes) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->extensions) {
res = RegSetValueExA(clsid_key, extensions_valuename, 0, REG_SZ,
(CONST BYTE*)(list->extensions),
strlen(list->extensions) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->formats) {
HKEY formats_key;
GUID const * const *format;
res = RegCreateKeyExW(clsid_key, formats_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
for (format=list->formats; *format; ++format)
{
HKEY format_key;
StringFromGUID2(*format, buf, 39);
//.........这里部分代码省略.........
示例2: win9x_service_un_install
//.........这里部分代码省略.........
if (RegCreateKey(HKEY_LOCAL_MACHINE, Win9xRegServ, &hk)!=ERROR_SUCCESS)
rc = 0;
if (rc)
{
char *sp, *path, *asp, *p;
int q = 0, q1, tmplen1, tmplen2, len = 1; /* '\0' */
build_service_arguments(&asp, argv, 1);
for(p=asp, tmplen1=0; *p; p++, tmplen1++)
if (*p == ' ') { q = 1; }
p++; len += tmplen1+1; /* binkd9x path & filename + (' ') */
if (q) { len += 2; }
tmplen2 = strlen(Win9xStartService);
len += tmplen2; /* Win9xStartService */
for (sp = p; *sp; sp++)
{
len++;
for(q1 = 0; *sp; sp++)
{
len++;
if (!q1 && *sp == ' ') { q1 = 1; len += 2; }
}
}
sp = path = (char *)malloc(len);
if (q) { *(sp++) = '"'; }
memcpy(sp, asp, tmplen1); sp += tmplen1;
if (q) { *(sp++) = '"'; }
*(sp++) = ' ';
memcpy(sp, Win9xStartService, tmplen2); sp += tmplen2;
for(; *p; p++)
{
*(sp++) = ' ';
if (strchr(p, ' ')) { *(sp++) = '"'; q = 1; } else { q = 0; }
for(;*p;p++) { *(sp++) = *p; }
if (q) { *(sp++) = '"'; }
}
*sp = '\0';
if (RegSetValueEx(hk, service_name, 0, REG_SZ, (unsigned char *)path, len-1) != ERROR_SUCCESS)
rc = 0;
free(path);
free(asp);
RegCloseKey(hk);
/* Store current directory */
if (rc)
{
sp = win9x_make_Win9xRegParm(service_name);
if (RegOpenKey(HKEY_LOCAL_MACHINE, sp, &hk)!=ERROR_SUCCESS)
if (RegCreateKey(HKEY_LOCAL_MACHINE, sp, &hk)!=ERROR_SUCCESS)
rc = 0;
if (rc)
{
j = GetCurrentDirectory(0, NULL);
path = (char *)malloc(j);
GetCurrentDirectory(j, path);
if (RegSetValueEx(hk, Win9xRegParm_Path, 0, REG_SZ, (unsigned char *)path, j-1) != ERROR_SUCCESS)
rc = 0;
free(path);
}
free(sp);
RegCloseKey(hk);
if (!rc) win9x_service_do_uninstall(service_name, 1); /* Rollback */
}
}
if (!rc)
Log((quiet_flag?0:-1), "Unable to store data in registry...%s", quiet_flag?"":"\n");
else
{
if (win9x_service_start(service_name))
{
if (!quiet_flag) Log(-1, "\'%s\' installed and started...\n", service_name);
}
else
{
rc = 0;
if (!quiet_flag)
{
Log(-1, "\'%s\' installed...\n", service_name);
Log(-1, "Unable to start service!\n");
}
}
}
return rc;
}
示例3: windowsOSVersionString
static void
windowsOSVersionString(char stringbuf[], size_t stringbuflen)
{
/* copy OS version to string buffer in 'uname -a' format */
OSVERSIONINFOEX osVersionInfo;
BOOL gotOsVersionInfoEx;
char windowsVersion[256] = "";
char hostname[256] = "";
char identifier[256] = "";
DWORD identifierSz = 256;
HKEY hKey;
ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
gotOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osVersionInfo);
if (gotOsVersionInfoEx == FALSE) {
GetVersionEx((OSVERSIONINFO *)&osVersionInfo);
}
switch (osVersionInfo.dwPlatformId) {
case VER_PLATFORM_WIN32_NT:
if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 2)) {
strcat(windowsVersion, "Server 2003");
} else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 1)) {
strcat(windowsVersion, "XP");
} else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 0)) {
strcat(windowsVersion, "2000");
} else if (osVersionInfo.dwMajorVersion <= 4) {
strcat(windowsVersion, "NT");
}
if (gotOsVersionInfoEx == TRUE) {
if (osVersionInfo.wProductType == VER_NT_WORKSTATION) {
if (osVersionInfo.dwMajorVersion == 4) {
strcat(windowsVersion, " Workstation 4.0");
} else if (osVersionInfo.wSuiteMask & VER_SUITE_PERSONAL) {
strcat(windowsVersion, " Home Edition");
} else {
strcat(windowsVersion, " Professional");
}
} else if (osVersionInfo.wProductType == VER_NT_SERVER) {
if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 2)) {
if (osVersionInfo.wSuiteMask & VER_SUITE_DATACENTER) {
strcat(windowsVersion, " Datacenter Edition");
} else if (osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
strcat(windowsVersion, " Enterprise Edition");
} else if (osVersionInfo.wSuiteMask == VER_SUITE_BLADE) {
strcat(windowsVersion, " Web Edition");
} else {
strcat(windowsVersion, " Standard Edition");
}
} else if ((osVersionInfo.dwMajorVersion == 5) && (osVersionInfo.dwMinorVersion == 0)) {
if (osVersionInfo.wSuiteMask & VER_SUITE_DATACENTER) {
strcat(windowsVersion, " Datacenter Server");
} else if (osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
strcat(windowsVersion, " Advanced Server");
} else {
strcat(windowsVersion, " Server");
}
} else {
if (osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
strcat(windowsVersion, " Server 4.0, Enterprise Edition");
} else {
strcat(windowsVersion, " Server 4.0");
}
}
}
} else {
char productType[80];
DWORD productTypeSz = 80;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
if (RegQueryValueEx(hKey, "ProductType", NULL, NULL, (LPBYTE) productType, &productTypeSz) == ERROR_SUCCESS) {
char versionStr[10];
if (strcmpi("WINNT", productType) == 0) {
strcat(windowsVersion, " Workstation");
} else if (strcmpi("LANMANNT", productType) == 0) {
strcat(windowsVersion, " Server");
} else if (strcmpi("SERVERNT", productType) == 0) {
strcat(windowsVersion, " Advanced Server");
}
sprintf(versionStr, " %d.%d", (int)osVersionInfo.dwMajorVersion, (int)osVersionInfo.dwMinorVersion);
strcat(windowsVersion, versionStr);
}
RegCloseKey(hKey);
}
}
break;
case VER_PLATFORM_WIN32_WINDOWS:
if ((osVersionInfo.dwMajorVersion == 4) && (osVersionInfo.dwMinorVersion == 90)) {
strcat(windowsVersion, "ME");
} else if ((osVersionInfo.dwMajorVersion == 4) && (osVersionInfo.dwMinorVersion == 10)) {
strcat(windowsVersion, "98");
if (osVersionInfo.szCSDVersion[1] == 'A') {
strcat(windowsVersion, " SE");
}
} else if ((osVersionInfo.dwMajorVersion == 4) && (osVersionInfo.dwMinorVersion == 0)) {
strcat(windowsVersion, "95");
if ((osVersionInfo.szCSDVersion[1] == 'C') || (osVersionInfo.szCSDVersion[1] == 'B')) {
strcat(windowsVersion, " OSR2");
}
//.........这里部分代码省略.........
示例4: wf_info_init
wfInfo* wf_info_init()
{
wfInfo* wfi;
wfi = (wfInfo*) malloc(sizeof(wfInfo));
ZeroMemory(wfi, sizeof(wfInfo));
if (wfi != NULL)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
wfi->mutex = CreateMutex(NULL, FALSE, NULL);
if (wfi->mutex == NULL)
{
WLog_ERR(TAG, "CreateMutex error: %d", GetLastError());
}
wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL);
wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL);
if (!wfi->updateThread)
{
WLog_ERR(TAG, "Failed to create update thread");
}
wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
//Set FPS
wfi->framesPerSecond = WF_INFO_DEFAULT_FPS;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
wfi->framesPerSecond = dwValue;
}
RegCloseKey(hKey);
//Set input toggle
wfi->input_disabled = FALSE;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
{
if (dwValue != 0)
wfi->input_disabled = TRUE;
}
}
RegCloseKey(hKey);
}
return wfi;
}
示例5: parse_command_line
int parse_command_line(char *cmd)
{
const char *run_key = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
const char *kernel = "kernel32.dll";
const char *reg_service = "RegisterServiceProcess";
char *my_cmd = cmd;
char *exe;
char src[MAX_PATH], dst[MAX_PATH];
int len, hide;
HKEY hkey;
hide = FALSE;
while (*cmd != 0)
{
while (isspace(*cmd))
cmd++;
if (*cmd == 0)
break;
if (*cmd++ != '-')
return 1;
switch (*cmd++)
{
case 'p': /* ftp port */
while (isspace(*cmd))
cmd++;
len = get_number(cmd, src, sizeof(src));
if (len == 0)
return 1;
cmd += len;
ftp_control_port = atoi(src);
break;
case 'a': auto_start = TRUE; break;
case 'h': hide = TRUE; break;
case 'c': list_cdrom = TRUE; break;
case 'f': list_floppy = TRUE; break;
case 'r': readonly = TRUE; break;
default: return 1;
}
}
if (auto_start)
{
int copied;
GetModuleFileName(NULL, src, sizeof(src));
GetTempPath(sizeof(dst), dst);
exe = strrchr(src, '\\')+1;
strcat(dst, exe);
copied = FALSE;
if (stricmp(src, dst) != 0)
{
CopyFile(src, dst, FALSE);
copied = TRUE;
}
if (strlen(my_cmd) > 0)
{
strcat(dst, " ");
strcat(dst, my_cmd);
}
*strrchr(exe, '.') = 0;
RegCreateKey(HKEY_CURRENT_USER, run_key, &hkey);
RegSetValueEx(hkey, exe, 0, REG_SZ, dst, strlen(dst));
RegCloseKey(hkey);
if (copied)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_FORCEOFFFEEDBACK;
CreateProcess(NULL, dst, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
exit(0);
}
}
if (hide)
{
DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
RegisterServiceProcess =
(void *) GetProcAddress(GetModuleHandle(kernel), reg_service);
if (RegisterServiceProcess)
RegisterServiceProcess(GetCurrentProcessId(), 1);
}
return 0;
}
示例6: main
main( int argc, char* argv[] )
{
DWORD i;
HKEY RemoteUsers;
HKEY RemoteLocalMachine;
LONG Status;
if( argc <= 1 ) {
printf( "\n******* Examining HKEY_LOCAL_MACHINE on local machine\n\n" );
ExamineKey( HKEY_LOCAL_MACHINE,
L"",
L"",
L"HKEY_LOCAL_MACHINE" );
printf( "\n******* Examining HKEY_USERS on local machine\n\n" );
ExamineKey( HKEY_USERS,
L"",
L"",
L"HKEY_USERS" );
printf( "\n******* Examining HKEY_CLASSES_ROOT on local machine\n\n" );
ExamineKey( HKEY_CLASSES_ROOT,
L"",
L"",
L"HKEY_CLASSES_ROOT" );
printf( "\n******* Examining HKEY_CURRENT_USER on local machine\n\n" );
ExamineKey( HKEY_CURRENT_USER,
L"",
L"",
L"HKEY_CURRENT_USER" );
} else {
for( i = 1; i < argc; i++ ) {
//
// printf( "Machine name = %s \n", argv[ i ] );
//
Status = RegConnectRegistry( argv[ i ],
HKEY_LOCAL_MACHINE,
&RemoteLocalMachine );
if( Status != ERROR_SUCCESS ) {
printf( MSG_ERROR_REG_CONNECT_REGISTRY, argv[i], Status );
continue;
}
Status = RegConnectRegistry( argv[ i ],
HKEY_USERS,
&RemoteUsers );
if( Status != ERROR_SUCCESS ) {
RegCloseKey( RemoteLocalMachine );
printf( MSG_ERROR_REG_CONNECT_REGISTRY, argv[i], Status );
continue;
}
printf( "\n******* Examining HKEY_LOCAL_MACHINE on %s \n\n", argv[i] );
ExamineKey( RemoteLocalMachine,
L"",
L"",
L"HKEY_LOCAL_MACHINE" );
printf( "\n******* Examining HKEY_USERS on %s \n\n", argv[i] );
ExamineKey( RemoteUsers,
L"",
L"",
L"HKEY_USERS" );
RegCloseKey( RemoteLocalMachine );
RegCloseKey( RemoteUsers );
}
}
}
示例7: GetRegistryKeys
int
GetRegistryKeys()
{
TCHAR windows_dir[MAX_PATH];
TCHAR temp_path[MAX_PATH];
TCHAR openvpn_path[MAX_PATH];
TCHAR profile_dir[MAX_PATH];
HKEY regkey;
if (!GetWindowsDirectory(windows_dir, _countof(windows_dir))) {
/* can't get windows dir */
ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
return(false);
}
if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, profile_dir) != S_OK) {
ShowLocalizedMsg(IDS_ERR_GET_PROFILE_DIR);
return(false);
}
/* Get path to OpenVPN installation. */
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\OpenVPN"), 0, KEY_READ, ®key)
!= ERROR_SUCCESS)
{
/* registry key not found */
ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
return(false);
}
if (!GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path)))
{
/* error reading registry value */
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
RegCloseKey(regkey);
return(false);
}
if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\'))
_tcscat(openvpn_path, _T("\\"));
/* an admin-defined global config dir defined in HKLM\OpenVPN\config_dir */
if (!GetRegistryValue(regkey, _T("config_dir"), o.global_config_dir, _countof(o.global_config_dir)))
{
/* use default = openvpnpath\config */
_sntprintf_0(o.global_config_dir, _T("%sconfig"), openvpn_path);
}
if (!GetRegistryValue(regkey, _T("ovpn_admin_group"), o.ovpn_admin_group, _countof(o.ovpn_admin_group)))
{
_tcsncpy(o.ovpn_admin_group, OVPN_ADMIN_GROUP, _countof(o.ovpn_admin_group));
}
RegCloseKey(regkey);
/* config_dir in user's profile by default */
_sntprintf_0(temp_path, _T("%s\\OpenVPN\\config"), profile_dir);
if (!GetRegKey(_T("config_dir"), o.config_dir,
temp_path, _countof(o.config_dir))) return(false);
if (!GetRegKey(_T("config_ext"), o.ext_string, _T("ovpn"), _countof(o.ext_string))) return(false);
_sntprintf_0(temp_path, _T("%sbin\\openvpn.exe"), openvpn_path);
if (!GetRegKey(_T("exe_path"), o.exe_path,
temp_path, _countof(o.exe_path))) return(false);
_sntprintf_0(temp_path, _T("%s\\OpenVPN\\log"), profile_dir);
if (!GetRegKey(_T("log_dir"), o.log_dir,
temp_path, _countof(o.log_dir))) return(false);
if (!GetRegKey(_T("log_append"), o.append_string, _T("0"), _countof(o.append_string))) return(false);
if (!GetRegKey(_T("priority"), o.priority_string,
_T("NORMAL_PRIORITY_CLASS"), _countof(o.priority_string))) return(false);
_sntprintf_0(temp_path, _T("%s\\system32\\notepad.exe"), windows_dir);
if (!GetRegKey(_T("log_viewer"), o.log_viewer,
temp_path, _countof(o.log_viewer))) return(false);
_sntprintf_0(temp_path, _T("%s\\system32\\notepad.exe"), windows_dir);
if (!GetRegKey(_T("editor"), o.editor,
temp_path, _countof(o.editor))) return(false);
if (!GetRegKey(_T("allow_edit"), o.allow_edit, _T("1"), _countof(o.allow_edit))) return(false);
if (!GetRegKey(_T("allow_service"), o.allow_service, _T("0"), _countof(o.allow_service))) return(false);
if (!GetRegKey(_T("allow_password"), o.allow_password, _T("1"), _countof(o.allow_password))) return(false);
if (!GetRegKey(_T("allow_proxy"), o.allow_proxy, _T("1"), _countof(o.allow_proxy))) return(false);
if (!GetRegKey(_T("service_only"), o.service_only, _T("0"), _countof(o.service_only))) return(false);
if (!GetRegKey(_T("show_balloon"), o.show_balloon, _T("1"), _countof(o.show_balloon))) return(false);
if (!GetRegKey(_T("silent_connection"), o.silent_connection, _T("0"), _countof(o.silent_connection))) return(false);
if (!GetRegKey(_T("show_script_window"), o.show_script_window, _T("1"), _countof(o.show_script_window))) return(false);
if (!GetRegKey(_T("disconnect_on_suspend"), o.disconnect_on_suspend, _T("0"),
_countof(o.disconnect_on_suspend))) return(false);
if (!GetRegKey(_T("passphrase_attempts"), o.psw_attempts_string, _T("3"),
_countof(o.psw_attempts_string))) return(false);
o.psw_attempts = _ttoi(o.psw_attempts_string);
//.........这里部分代码省略.........
示例8: WatchKey
// main thread for monitoring keys
DWORD WatchKey(PREGMON p)
{
HANDLE hEvent;
HKEY hKey;
LONG ret;
Output(0, _T("Monitoring HKEY %x\\%s\n"),
p->hMainKey, p->szSubkey);
/*
WinReg.h
RegOpenKeyEx :
Opens the specified registry key.
Note that key names are not case sensitive.
To perform transacted registry operations on a key,
call the RegOpenKeyTransacted function.
RegOpenKeyTransacted :
Opens the specified registry key and associates it with a transaction.
Note that key names are not case sensitive.
*/
ret = RegOpenKeyEx(
p->hMainKey,
p->szSubkey,
0,
KEY_READ | KEY_NOTIFY,
&hKey);
if (ret != ERROR_SUCCESS)
{
return -1;
}
// create an event that will get signaled by the system
// when a change is made to the monitored key
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hEvent == NULL)
{
return -1;
}
// this event gets signaled if a user enters CTRL+C to stop
while(WaitForSingleObject(g_hStopEvent, 1) != WAIT_OBJECT_0)
{
UpdateTime();
// register to receive change notification
ret = RegNotifyChangeKeyValue(hKey,
TRUE,
REG_CHANGE_FLAGS,
hEvent,
TRUE);
if (ret != ERROR_SUCCESS)
{
break;
}
if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
{
break;
}
GetRegistryChanges(hKey);
}
Output(0, _T("Closing HKEY %x\\%s\n"),
p->hMainKey, p->szSubkey);
RegCloseKey(hKey);
CloseHandle(hEvent);
return 0;
}
示例9: memset
void CKeyboardLayout::LoadScanCodeMap(const HKEY_TYPE hkeyType)
{
memset(m_ScanCodeMap[hkeyType], 0, sizeof(m_ScanCodeMap[hkeyType]));
memset(m_CurrentScanCodeMap[hkeyType], 0, sizeof(m_CurrentScanCodeMap[hkeyType]));
CString szSubKey;
CString szValueName;
HKEY hKey = HKEY_LOCAL_MACHINE;
switch (hkeyType) {
case CURRENT_USER:
hKey = HKEY_CURRENT_USER;
szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT);
break;
case LOCAL_MACHINE:
szSubKey.LoadString(IDS_REGSUBKEY_KEYBOARD_LAYOUT_ANY_USER);
break;
default:
return;
}
szValueName.LoadString(IDS_SCANCODE_MAP);
HKEY hkResult = NULL;
if (RegOpenKeyEx(hKey, szSubKey, 0, KEY_QUERY_VALUE, &hkResult) == ERROR_SUCCESS) {
// get data size
DWORD dwType = REG_BINARY;
DWORD dwData = 0;
RegQueryValueEx(hkResult, szValueName, NULL, &dwType, NULL, &dwData);
// get data
LPBYTE lpData = new BYTE[dwData];
if (lpData) {
RegQueryValueEx(hkResult, szValueName, NULL, &dwType, lpData, &dwData);
}
RegCloseKey(hkResult);
if (lpData && dwData) {
DWORD offset = 0;
offset += 8; // skip Version Information and Flags
DWORD *pdwMappings = (DWORD *)(lpData + offset);
offset += 4; // skip Number of Mappings
DWORD *pdwNullTerminator = (DWORD *)(lpData + dwData - 4);
if (4 * *pdwMappings + 12 != dwData) {
// illegal data
} else if (*pdwNullTerminator != 0) {
// illegal data
} else {
while (offset < dwData - 4) {
ScanCodeMapping *pMapping = (ScanCodeMapping *)(lpData + offset);
offset += 4; // go to next data
m_CurrentScanCodeMap[hkeyType][Prefix2ID(pMapping->original.nPrefix)][pMapping->original.nScanCode].nPrefix = pMapping->current.nPrefix;
m_CurrentScanCodeMap[hkeyType][Prefix2ID(pMapping->original.nPrefix)][pMapping->original.nScanCode].nScanCode = pMapping->current.nScanCode;
m_ScanCodeMap[hkeyType][Prefix2ID(pMapping->original.nPrefix)][pMapping->original.nScanCode].nPrefix = pMapping->current.nPrefix;
m_ScanCodeMap[hkeyType][Prefix2ID(pMapping->original.nPrefix)][pMapping->original.nScanCode].nScanCode = pMapping->current.nScanCode;
}
}
}
delete[] lpData;
lpData = NULL;
}
}
示例10: GetPublicJREHome
static jboolean
GetPublicJREHome(char *buf, jint bufsize)
{
HKEY key, subkey;
char version[MAXPATHLEN];
/*
* Note: There is a very similar implementation of the following
* registry reading code in the Windows java control panel (javacp.cpl).
* If there are bugs here, a similar bug probably exists there. Hence,
* changes here require inspection there.
*/
/* Find the current version of the JRE */
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY, 0, KEY_READ, &key) != 0) {
JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY);
return JNI_FALSE;
}
if (!GetStringFromRegistry(key, "CurrentVersion",
version, sizeof(version))) {
JLI_ReportErrorMessage(REG_ERROR2, JRE_KEY);
RegCloseKey(key);
return JNI_FALSE;
}
if (JLI_StrCmp(version, GetDotVersion()) != 0) {
JLI_ReportErrorMessage(REG_ERROR3, JRE_KEY, version, GetDotVersion()
);
RegCloseKey(key);
return JNI_FALSE;
}
/* Find directory where the current version is installed. */
if (RegOpenKeyEx(key, version, 0, KEY_READ, &subkey) != 0) {
JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY, version);
RegCloseKey(key);
return JNI_FALSE;
}
if (!GetStringFromRegistry(subkey, "JavaHome", buf, bufsize)) {
JLI_ReportErrorMessage(REG_ERROR4, JRE_KEY, version);
RegCloseKey(key);
RegCloseKey(subkey);
return JNI_FALSE;
}
if (JLI_IsTraceLauncher()) {
char micro[MAXPATHLEN];
if (!GetStringFromRegistry(subkey, "MicroVersion", micro,
sizeof(micro))) {
printf("Warning: Can't read MicroVersion\n");
micro[0] = '\0';
}
printf("Version major.minor.micro = %s.%s\n", version, micro);
}
RegCloseKey(key);
RegCloseKey(subkey);
return JNI_TRUE;
}
示例11: GRE_GetPathFromRegKey
PRBool
GRE_GetPathFromRegKey(HKEY aRegKey,
const GREVersionRange *versions,
PRUint32 versionsLength,
const GREProperty *properties,
PRUint32 propertiesLength,
char* aBuffer, PRUint32 aBufLen)
{
// Formerly, GREs were registered at the registry key
// HKLM/Software/mozilla.org/GRE/<version> valuepair GreHome=Path.
// Nowadays, they are registered in any subkey of
// Software/mozilla.org/GRE, with the following valuepairs:
// Version=<version> (REG_SZ)
// GreHome=<path> (REG_SZ or REG_EXPAND_SZ)
// <Property>=<value> (REG_SZ)
//
// Additional meta-info may be available in the future, including
// localization info and other information which might be pertinent
// to selecting one GRE over another.
//
// When a GRE is being registered, it should try to register itself at
// HKLM/Software/mozilla.org/GRE/<Version> first, to preserve compatibility
// with older glue. If this key is already taken (i.e. there is more than
// one GRE of that version installed), it should append a unique number to
// the version, for example:
// 1.1 (already in use), 1.1_1, 1.1_2, etc...
DWORD i = 0;
while (PR_TRUE) {
char name[MAXPATHLEN + 1];
DWORD nameLen = MAXPATHLEN;
if (::RegEnumKeyEx(aRegKey, i, name, &nameLen, NULL, NULL, NULL, NULL) !=
ERROR_SUCCESS) {
break;
}
HKEY subKey = NULL;
if (::RegOpenKeyEx(aRegKey, name, 0, KEY_QUERY_VALUE, &subKey) !=
ERROR_SUCCESS) {
continue;
}
char version[40];
DWORD versionlen = 40;
char pathbuf[MAXPATHLEN];
DWORD pathlen;
DWORD pathtype;
PRBool ok = PR_FALSE;
if (::RegQueryValueEx(subKey, "Version", NULL, NULL,
(BYTE*) version, &versionlen) == ERROR_SUCCESS &&
CheckVersion(version, versions, versionsLength)) {
ok = PR_TRUE;
const GREProperty *props = properties;
const GREProperty *propsEnd = properties + propertiesLength;
for (; ok && props < propsEnd; ++props) {
pathlen = sizeof(pathbuf);
if (::RegQueryValueEx(subKey, props->property, NULL, &pathtype,
(BYTE*) pathbuf, &pathlen) != ERROR_SUCCESS ||
strcmp(pathbuf, props->value))
ok = PR_FALSE;
}
pathlen = sizeof(pathbuf);
if (ok &&
(!::RegQueryValueEx(subKey, "GreHome", NULL, &pathtype,
(BYTE*) pathbuf, &pathlen) == ERROR_SUCCESS ||
!*pathbuf ||
!CopyWithEnvExpansion(aBuffer, pathbuf, aBufLen, pathtype))) {
ok = PR_FALSE;
}
else if (!safe_strncat(aBuffer, "\\" XPCOM_DLL, aBufLen) ||
access(aBuffer, R_OK)) {
ok = PR_FALSE;
}
}
RegCloseKey(subKey);
if (ok)
return PR_TRUE;
++i;
}
aBuffer[0] = '\0';
return PR_FALSE;
}
示例12: RAND_poll
//.........这里部分代码省略.........
* return instead of ERROR_SUCCESS.
*/
LONG rc=ERROR_MORE_DATA;
char * buf=NULL;
DWORD bufsz=0;
DWORD length;
while (rc == ERROR_MORE_DATA)
{
buf = realloc(buf,bufsz+8192);
if (!buf)
break;
bufsz += 8192;
length = bufsz;
rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, TEXT("Global"),
NULL, NULL, buf, &length);
}
if (rc == ERROR_SUCCESS)
{
/* For entropy count assume only least significant
* byte of each DWORD is random.
*/
RAND_add(&length, sizeof(length), 0);
RAND_add(buf, length, length / 4.0);
/* Close the Registry Key to allow Windows to cleanup/close
* the open handle
* Note: The 'HKEY_PERFORMANCE_DATA' key is implicitly opened
* when the RegQueryValueEx above is done. However, if
* it is not explicitly closed, it can cause disk
* partition manipulation problems.
*/
RegCloseKey(HKEY_PERFORMANCE_DATA);
}
if (buf)
free(buf);
}
#endif
if (advapi)
{
/*
* If it's available, then it's available in both ANSI
* and UNICODE flavors even in Win9x, documentation says.
* We favor Unicode...
*/
acquire = (CRYPTACQUIRECONTEXTW) GetProcAddress(advapi,
"CryptAcquireContextW");
gen = (CRYPTGENRANDOM) GetProcAddress(advapi,
"CryptGenRandom");
release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi,
"CryptReleaseContext");
}
if (acquire && gen && release)
{
/* poll the CryptoAPI PRNG */
/* The CryptoAPI returns sizeof(buf) bytes of randomness */
if (acquire(&hProvider, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
{
if (gen(hProvider, sizeof(buf), buf) != 0)
{
RAND_add(buf, sizeof(buf), 0);
good = 1;
示例13: GetSystemInfo
void BOT_INFO::resetSystemInfo()
{
// CPU type
SYSTEM_INFO si;
GetSystemInfo(&si);
processor = si.dwProcessorType;
// Windows registration name
{
char buffer[40];
// Get platform
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
Uint32 PlatformId = osvi.dwPlatformId;
// Prepare for registry access
HKEY key; // Handle to a session with a registry key
Uint32 buflen; // Length of the buffer
Uint32 type; // Type will contain type of data transfered
if (PlatformId != VER_PLATFORM_WIN32_NT)
{
// Look up Windows 9x or Windows 3.1 version information
RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", (HKEY*)&key);
}
else
{
// Look up Windows NT version information
RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", (HKEY*)&key);
}
buflen = 40;
RegQueryValueEx(key, "RegisteredOwner", NULL, &type, (BYTE*)&buffer, &buflen);
strncpy(regName, buffer, 40);
buflen = 40;
RegQueryValueEx(key, "RegisteredOrganization", NULL, &type, (BYTE*)&buffer, &buflen);
strncpy(regOrg, buffer, 40);
RegCloseKey(key);
}
// Timezone Bias
TIME_ZONE_INFORMATION tzi;
GetTimeZoneInformation(&tzi);
timeZoneBias = (SHORT)tzi.Bias;
// Permission ID
permissionID = getSetting32(HKEY_LOCAL_MACHINE, "SOFTWARE", "D2");
// Install some SubSpace registry keys
if (permissionID == -1)
{
do
{
permissionID = (GetTickCount() ^ 0xAAAAAAAA) * 0x5f346d + 0x5abcdef;
}
while (!permissionID || permissionID == 1 || permissionID == -1);
setSetting32(HKEY_LOCAL_MACHINE, "SOFTWARE", "D2", permissionID);
}
// Machine ID
GetVolumeInformation("C:\\", NULL, 0, &machineID, NULL, NULL, NULL, 0);
if (!machineID || machineID == 1 || machineID == -1)
{
machineID = getSetting32(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProductCode");
if (!machineID || machineID == 1 || machineID == -1)
{
machineID = permissionID;
setSetting32(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProductCode", machineID);
}
}
if (machineID > 0x7fffffff) machineID += 0x7fffffff;
setSetting32(HKEY_LOCAL_MACHINE, "SOFTWARE", "D1", machineID);
}
示例14: register_converters
/***********************************************************************
* register_converters
*/
static HRESULT register_converters(struct regsvr_converter const *list)
{
LONG res = ERROR_SUCCESS;
HKEY coclass_key;
WCHAR buf[39];
HKEY converters_key;
HKEY instance_key;
res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
if (res == ERROR_SUCCESS) {
StringFromGUID2(&CATID_WICFormatConverters, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &converters_key, NULL);
if (res == ERROR_SUCCESS)
{
res = RegCreateKeyExW(converters_key, instance_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_coclass_key;
}
if (res != ERROR_SUCCESS)
RegCloseKey(coclass_key);
}
if (res != ERROR_SUCCESS) goto error_return;
for (; res == ERROR_SUCCESS && list->clsid; ++list) {
HKEY clsid_key;
HKEY instance_clsid_key;
StringFromGUID2(list->clsid, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_coclass_key;
StringFromGUID2(list->clsid, buf, 39);
res = RegCreateKeyExW(instance_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &instance_clsid_key, NULL);
if (res == ERROR_SUCCESS) {
res = RegSetValueExW(instance_clsid_key, clsid_valuename, 0, REG_SZ,
(CONST BYTE*)(buf), 78);
RegCloseKey(instance_clsid_key);
}
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
if (list->author) {
res = RegSetValueExA(clsid_key, author_valuename, 0, REG_SZ,
(CONST BYTE*)(list->author),
strlen(list->author) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->friendlyname) {
res = RegSetValueExA(clsid_key, friendlyname_valuename, 0, REG_SZ,
(CONST BYTE*)(list->friendlyname),
strlen(list->friendlyname) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->vendor) {
StringFromGUID2(list->vendor, buf, 39);
res = RegSetValueExW(clsid_key, vendor_valuename, 0, REG_SZ,
(CONST BYTE*)(buf), 78);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->version) {
res = RegSetValueExA(clsid_key, version_valuename, 0, REG_SZ,
(CONST BYTE*)(list->version),
strlen(list->version) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->formats) {
HKEY formats_key;
GUID const * const *format;
res = RegCreateKeyExW(clsid_key, pixelformats_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
for (format=list->formats; *format; ++format)
{
HKEY format_key;
StringFromGUID2(*format, buf, 39);
res = RegCreateKeyExW(formats_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &format_key, NULL);
if (res != ERROR_SUCCESS) break;
RegCloseKey(format_key);
}
RegCloseKey(formats_key);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
error_close_clsid_key:
RegCloseKey(clsid_key);
}
error_close_coclass_key:
//.........这里部分代码省略.........
示例15: WNetEnumCachedPasswords
UINT WINAPI WNetEnumCachedPasswords(
LPSTR pbPrefix, /* [in] prefix to filter cache entries */
WORD cbPrefix, /* [in] number of bytes in Prefix substring */
BYTE nType, /* [in] match the Type ID of the entry */
ENUMPASSWORDPROC enumPasswordProc, /* [in] callback function */
DWORD param) /* [in] parameter passed to enum function */
{
HKEY hkey;
DWORD r, type, val_sz, data_sz, i, j, size;
PASSWORD_CACHE_ENTRY *entry;
CHAR val[256], prefix[6];
WARN( "(%s, %d, %d, %p, 0x%08x) totally insecure\n",
debugstr_an(pbPrefix,cbPrefix), cbPrefix,
nType, enumPasswordProc, param );
/* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
if( r )
return WN_ACCESS_DENIED;
sprintf(prefix, "X-%02X-", nType );
for( i=0; ; i++ )
{
val_sz = sizeof val;
data_sz = 0;
type = 0;
val[0] = 0;
r = RegEnumValueA( hkey, i, val, &val_sz, NULL, &type, NULL, &data_sz );
if( r != ERROR_SUCCESS )
break;
if( type != REG_BINARY )
continue;
/* check the value is in the format we expect */
if( val_sz < sizeof prefix )
continue;
if( memcmp( prefix, val, 5 ) )
continue;
/* decode the value */
for(j=5; j<val_sz; j+=2 )
{
signed char hi = ctox( val[j] ), lo = ctox( val[j+1] );
if( ( hi < 0 ) || ( lo < 0 ) )
break;
val[(j-5)/2] = (hi<<4) | lo;
}
/* find the decoded length */
val_sz = (j - 5)/2;
val[val_sz]=0;
if( val_sz < cbPrefix )
continue;
/* check the prefix matches */
if( memcmp(val, pbPrefix, cbPrefix) )
continue;
/* read the value data */
size = offsetof( PASSWORD_CACHE_ENTRY, abResource[val_sz + data_sz] );
entry = HeapAlloc( GetProcessHeap(), 0, size );
memcpy( entry->abResource, val, val_sz );
entry->cbEntry = size;
entry->cbResource = val_sz;
entry->cbPassword = data_sz;
entry->iEntry = i;
entry->nType = nType;
r = RegEnumValueA( hkey, i, NULL, &val_sz, NULL, &type,
&entry->abResource[val_sz], &data_sz );
if( r == ERROR_SUCCESS )
enumPasswordProc( entry, param );
HeapFree( GetProcessHeap(), 0, entry );
}
RegCloseKey( hkey );
return WN_SUCCESS;
}