本文整理汇总了C++中RegOpenKeyEx函数的典型用法代码示例。如果您正苦于以下问题:C++ RegOpenKeyEx函数的具体用法?C++ RegOpenKeyEx怎么用?C++ RegOpenKeyEx使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegOpenKeyEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ui_doinstall
int ui_doinstall(HANDLE hFile,int offset,header *head, section *sec, entry *ent, uninstall_header *uhead)
{
TCHAR tmpbuf[MAX_PATH];
int ret = 3;
m_hFile=hFile;
m_offset=offset;
m_section=sec;
m_entry=ent;
m_header=head;
if (!uhead) {
if (noisy) {
noisy=!(head->silent_install);
} else {
head->silent_install = !noisy;
}
/* Setup localized strings */
if ((g_strings = getStrings(NULL)) == NULL) {
GETRESOURCE(tmpbuf, JAVAWS_ERROR_STRINGTABLE);
if (noisy) MessageBox(NULL,tmpbuf,g_caption,MB_OK|MB_ICONWARNING);
}
_tcscpy(tmpbuf, m_header->name);
process_string(m_header->name, tmpbuf, NULL);
_tcscpy(tmpbuf, m_header->licensetext);
process_string(m_header->licensetext, tmpbuf, NULL);
_tcscpy(tmpbuf, m_header->componenttext);
process_string(m_header->componenttext, tmpbuf, NULL);
_tcscpy(tmpbuf, m_header->text);
process_string(m_header->text, tmpbuf, NULL);
}
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
m_uninstheader=uhead;
if (uhead)
{
INT32 args[] = { (INT32)m_uninstheader->name };
g_strings = getStrings(NULL);
_tcscpy(tmpbuf, m_uninstheader->uninstalltext);
process_string(m_uninstheader->uninstalltext, tmpbuf, NULL);
GETRESOURCE2(tmpbuf, JAVAWS_MESSAGE_UNINSTALL, args);
wsprintf(g_caption,tmpbuf);
return DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_INST),GetDesktopWindow(),DialogProcUninstall);
}
else
#endif
{
TCHAR buf[MAX_PATH];
int st=0;
state_install_directory[0]=0;
if (head->install_reg_key[0])
{
HKEY hKey;
if ( RegOpenKeyEx((HKEY)head->install_reg_rootkey,head->install_reg_key,0,KEY_READ,&hKey) == ERROR_SUCCESS)
{
int l = sizeof(buf);
int t=REG_SZ;
if (RegQueryValueEx(hKey,head->install_reg_value,NULL,&t,buf,&l ) == ERROR_SUCCESS && t == REG_SZ && buf[0])
{
LPTSTR e;
LPTSTR p=buf;
while (*p && *p != _T('\"')) p=CharNext(p);
if (*p)
{
LPTSTR p2;
p=CharNext(p);
p2 = p;
while (*p2 && *p2 != _T('\"')) p2=CharNext(p2);
if (*p2)
{
*p2=0;
}
else p=buf;
}
else p=buf;
// p is the path now, check for .exe extension
e=p;
while (*e) e=CharNext(e);
while (e>p && *e != _T('.') && *e != _T('\\')) e=CharPrev(p, e);
if (*e ==_T('.'))
{
if ((e[1] == _T('e') || e[1]==_T('E')) &&
(e[2] == _T('x') || e[2]==_T('X')) &&
(e[3] == _T('e') || e[3]==_T('E'))) // check extension
{
DWORD d;
e[4]=0;
d=GetFileAttributes(p); // get the file attributes
if (d == 0xFFFFFFFFF || !(d&FILE_ATTRIBUTE_DIRECTORY)) // if not exists, or not directory, then remove suffix
{
while (e>p && *e != _T('\\')) e=CharPrev(p, e);
if (*e == _T('\\')) *e=0;
}
}
}
_tcscpy(state_install_directory,buf);
}
RegCloseKey(hKey);
//.........这里部分代码省略.........
示例2: readCpuCounters
int readCpuCounters(SFLHost_cpu_counters *cpu) {
int gotData = NO;
uint32_t i = 0;
PPDH_RAW_COUNTER_ITEM thread = NULL, processor = NULL;
DWORD dwRet,cbData = sizeof(DWORD);
HKEY hkey;
cpu->cpu_user = (uint32_t)readSingleCounter("\\Processor(_Total)\\% User Time");
cpu->cpu_system = (uint32_t)readSingleCounter("\\Processor(_Total)\\% Privileged Time");
cpu->cpu_idle = (uint32_t)readSingleCounter("\\Processor(_Total)\\% Idle Time");
cpu->cpu_intr = (uint32_t)readSingleCounter("\\Processor(_Total)\\% Interrupt Time");
cpu->interrupts = (uint32_t)readSingleCounter("\\Processor(_Total)\\Interrupts/sec");
cpu->contexts = (uint32_t)readSingleCounter("\\System\\Context Switches/sec");
cpu->uptime = (uint32_t)readFormattedCounter("\\System\\System Up Time");
cpu->cpu_num = readMultiCounter("\\Processor(*)\\% Processor Time",&processor);
// see http://support.microsoft.com/kb/888282 for ways to determine CPU speed
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"hardware\\description\\system\\centralprocessor\\0",
0,
KEY_QUERY_VALUE,
&hkey);
if(dwRet == ERROR_SUCCESS) {
dwRet = RegQueryValueEx( hkey,
"~MHz",
NULL,
NULL,
(LPBYTE) &cpu->cpu_speed,
&cbData );
if(dwRet != ERROR_SUCCESS) cpu->cpu_speed = -1;
}
cpu->proc_total = readMultiCounter("\\Thread(*)\\Thread State",&thread);
cpu->proc_run = 0;
if(thread){
for(i = 0; i < cpu->proc_total; i++){
if(thread[i].RawValue.FirstValue == 2 && strncmp("Idle",thread[i].szName,4) != 0){
cpu->proc_run++;
}
}
}
//These have no obvious Windows equivalent
cpu->cpu_sintr = UNKNOWN_COUNTER;
cpu->cpu_nice = UNKNOWN_COUNTER;
cpu->cpu_wio = UNKNOWN_COUNTER;
cpu->load_one = UNKNOWN_FLOAT;
cpu->load_five = UNKNOWN_FLOAT;
cpu->load_fifteen = UNKNOWN_FLOAT;
MyLog(LOG_INFO,"readCpuCounters:\n\tuptime:\t\t%lus\n\tcpu_num:\t%d\n\tcpu speed:\t%d MHz\n\tuser: %lu\n\tsystem: %lu\n\tidle: %lu\n\tirq: %lu\n\tthreads_total: %lu\n\tthreads_running: %lu\n",
cpu->uptime,cpu->cpu_num,cpu->cpu_speed,cpu->cpu_user,cpu->cpu_system,cpu->cpu_idle,cpu->cpu_intr,cpu->proc_total,cpu->proc_run);
if(thread){
free(thread);
}
if(processor){
free(processor);
}
gotData = YES;
return gotData;
}
示例3: identify_system_timezone
static const char *
identify_system_timezone(void)
{
int i;
char tzname[128];
char localtzname[256];
time_t t = time(NULL);
struct tm *tm = localtime(&t);
HKEY rootKey;
int idx;
if (!tm)
{
ereport(LOG,
(errmsg("could not identify system time zone: localtime() failed"),
errdetail("The PostgreSQL time zone will be set to \"%s\".",
"GMT"),
errhint("You can specify the correct timezone in postgresql.conf.")));
return NULL; /* go to GMT */
}
memset(tzname, 0, sizeof(tzname));
strftime(tzname, sizeof(tzname) - 1, "%Z", tm);
for (i = 0; win32_tzmap[i].stdname != NULL; i++)
{
if (strcmp(tzname, win32_tzmap[i].stdname) == 0 ||
strcmp(tzname, win32_tzmap[i].dstname) == 0)
{
elog(DEBUG4, "TZ \"%s\" matches system time zone \"%s\"",
win32_tzmap[i].pgtzname, tzname);
return win32_tzmap[i].pgtzname;
}
}
/*
* Localized Windows versions return localized names for the timezone.
* Scan the registry to find the English name, and then try matching
* against our table again.
*/
memset(localtzname, 0, sizeof(localtzname));
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
0,
KEY_READ,
&rootKey) != ERROR_SUCCESS)
{
ereport(LOG,
(errmsg("could not open registry key to identify system time zone: %i",
(int) GetLastError()),
errdetail("The PostgreSQL time zone will be set to \"%s\".",
"GMT"),
errhint("You can specify the correct timezone in postgresql.conf.")));
return NULL; /* go to GMT */
}
for (idx = 0;; idx++)
{
char keyname[256];
char zonename[256];
DWORD namesize;
FILETIME lastwrite;
HKEY key;
LONG r;
memset(keyname, 0, sizeof(keyname));
namesize = sizeof(keyname);
if ((r = RegEnumKeyEx(rootKey,
idx,
keyname,
&namesize,
NULL,
NULL,
NULL,
&lastwrite)) != ERROR_SUCCESS)
{
if (r == ERROR_NO_MORE_ITEMS)
break;
ereport(LOG,
(errmsg_internal("could not enumerate registry subkeys to identify system time zone: %i", (int) r)));
break;
}
if ((r = RegOpenKeyEx(rootKey, keyname, 0, KEY_READ, &key)) != ERROR_SUCCESS)
{
ereport(LOG,
(errmsg_internal("could not open registry subkey to identify system time zone: %i", (int) r)));
break;
}
memset(zonename, 0, sizeof(zonename));
namesize = sizeof(zonename);
if ((r = RegQueryValueEx(key, "Std", NULL, NULL, zonename, &namesize)) != ERROR_SUCCESS)
{
ereport(LOG,
(errmsg_internal("could not query value for key \"std\" to identify system time zone \"%s\": %i",
keyname, (int) r)));
RegCloseKey(key);
continue; /* Proceed to look at the next timezone */
}
//.........这里部分代码省略.........
示例4: Py_Initialize
void CPythonEngine::init()
{
if (!initialised)
{
initialised = 1;
/* Initialize the Python interpreter.*/
Py_Initialize();
PyEval_InitThreads();
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
/* Initialize TA Python env. */
Py_InitModule("tibiaauto", Methods_tibiaauto);
Py_InitModule("tareader", Methods_tareader);
Py_InitModule("tasender", Methods_tasender);
Py_InitModule("tamap", Methods_tamap);
Py_InitModule("taregexp", Methods_taregexp);
Py_InitModule("taalice", Methods_taalice);
Py_InitModule("taitem", Methods_taitem);
Py_InitModule("tacrstat", Methods_tacrstat);
Py_InitModule("takernel", Methods_takernel);
Py_InitModule("tapacket", Methods_tapacket);
PyRun_SimpleString("import tibiaauto");
PyRun_SimpleString("import tareader");
PyRun_SimpleString("import tasender");
PyRun_SimpleString("import tamap");
PyRun_SimpleString("import taregexp");
PyRun_SimpleString("import taalice");
PyRun_SimpleString("import taitem");
PyRun_SimpleString("import tacrstat");
PyRun_SimpleString("import takernel");
PyRun_SimpleString("import sys");
PyRun_SimpleString("import time");
char installPath[1024];
unsigned long installPathLen = 1023;
installPath[0] = '\0';
HKEY hkey = NULL;
if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Tibia Auto\\", 0, KEY_READ, &hkey))
{
RegQueryValueEx(hkey, TEXT("Install_Dir"), NULL, NULL, (unsigned char *)installPath, &installPathLen);
RegCloseKey(hkey);
}
if (!strlen(installPath))
{
::MessageBox(0, "ERROR! Unable to read TA install directory! Please reinstall!", "ERROR", 0);
PostQuitMessage(-1);
return;
}
char pathBuf[2048];
sprintf(pathBuf, "%s\\tascripts\\tautil.py", installPath);
// load tautil.py
FILE *f = fopen(pathBuf, "r");
if (f)
{
fseek(f, 0, SEEK_END);
int fileSize = ftell(f);
fseek(f, 0, SEEK_SET);
char *fileBuf = (char *)malloc(fileSize + 1);
memset(fileBuf, 0, fileSize + 1);
fread(fileBuf, 1, fileSize, f);
int ret = PyRun_SimpleString(fileBuf);
if (ret == -1)
AfxMessageBox("Loading tautil.py script failed!");
fclose(f);
}
else
{
AfxMessageBox("Unable to find tascripts\\tautil.py!");
}
PyGILState_Release(gstate);
InitializeCriticalSection(&ScriptEngineCriticalSection);
// now load all scripts from 'tascripts' subdirectory
sprintf(pathBuf, "%s\\tascripts\\*.py", installPath);
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile(pathBuf, &findFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
char buf[1024];
do
{
snprintf(buf, 1023, "%s\\tascripts\\%s", installPath, findFileData.cFileName);
// tautil.py will be loaded in a special way
if (!strstr(buf, "tascripts\\tautil.py"))
loadScript(buf);
}
while (FindNextFile(hFind, &findFileData));
FindClose(hFind);
//.........这里部分代码省略.........
示例5: smpd_get_all_smpd_data
int smpd_get_all_smpd_data(smpd_data_t **data)
{
#ifdef HAVE_WINDOWS_H
HKEY tkey;
DWORD result;
LONG enum_result;
char name[SMPD_MAX_NAME_LENGTH], value[SMPD_MAX_VALUE_LENGTH];
DWORD name_length, value_length, index;
smpd_data_t *list, *item;
char err_msg[512];
smpd_enter_fn(FCNAME);
if (data == NULL)
{
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SMPD_REGISTRY_KEY, 0, KEY_READ, &tkey);
if (result != ERROR_SUCCESS)
{
/* No key therefore no settings */
/* No access to the key, therefore no soup for you */
*data = NULL;
smpd_exit_fn(FCNAME);
return SMPD_SUCCESS;
}
list = NULL;
index = 0;
name_length = SMPD_MAX_NAME_LENGTH;
value_length = SMPD_MAX_VALUE_LENGTH;
enum_result = RegEnumValue(tkey, index, name, &name_length, NULL, NULL, (LPBYTE)value, &value_length);
while (enum_result == ERROR_SUCCESS)
{
item = (smpd_data_t*)MPIU_Malloc(sizeof(smpd_data_t));
if (item == NULL)
{
*data = NULL;
result = RegCloseKey(tkey);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
memcpy(item->name, name, SMPD_MAX_NAME_LENGTH);
memcpy(item->value, value, SMPD_MAX_VALUE_LENGTH);
item->next = list;
list = item;
index++;
name_length = SMPD_MAX_NAME_LENGTH;
value_length = SMPD_MAX_VALUE_LENGTH;
enum_result = RegEnumValue(tkey, index, name, &name_length, NULL, NULL, (LPBYTE)value, &value_length);
}
result = RegCloseKey(tkey);
if (result != ERROR_SUCCESS)
{
smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_LOCAL_MACHINE\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
smpd_err_printf("%s\n", err_msg);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
*data = list;
smpd_exit_fn(FCNAME);
return SMPD_SUCCESS;
#else
smpd_enter_fn(FCNAME);
if (data == NULL)
{
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
*data = NULL;
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
#endif
}
示例6: EDT_UtilReg_LogPermissions
int EDT_UtilReg_LogPermissions(HKEY hRootKey, const wchar_t *wzKey)
{
int iReturnCode = EDT_OK;
int err = ERROR_SUCCESS;
HKEY hRegKey;
LOG_ENTER();
LOG_TIME(L"registry key (%ls\\%ls) --> \n",hRootKey==HKEY_CURRENT_USER?L"HKCU":L"HKLM",wzKey);
if(ERROR_SUCCESS != (err = RegOpenKeyEx(hRootKey, wzKey, 0L, KEY_READ , &hRegKey)))
{
if(err != ERROR_FILE_NOT_FOUND)
{
LOG_ERRORCODE(L"RegOpenKeyEx failed",err);
return EDT_ERR_REGISTRY_READ_FAILED;
}
else
{
LOG_EXIT(L"NOT FOUND\n");
return EDT_ERR_REGISTRY_NOT_FOUND;
}
}
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
DWORD lcbSecurityDescriptor = 0;
if(ERROR_INSUFFICIENT_BUFFER == (err = RegGetKeySecurity(hRegKey, DACL_SECURITY_INFORMATION, pSecurityDescriptor, &lcbSecurityDescriptor)))
{
pSecurityDescriptor = (PSECURITY_DESCRIPTOR)malloc(lcbSecurityDescriptor);
if(ERROR_SUCCESS != (err = RegGetKeySecurity(hRegKey, DACL_SECURITY_INFORMATION, pSecurityDescriptor, &lcbSecurityDescriptor)))
{
LOG_ERRORCODE(L"RegQueryValueEx failed",err);
iReturnCode = EDT_ERR_REGISTRY_READ_FAILED;
}
else
{
BOOL bDaclPresent = FALSE;
BOOL bDaclDefaulted = FALSE;
PACL pDacl = NULL;
GetSecurityDescriptorDacl(pSecurityDescriptor, &bDaclPresent, &pDacl, &bDaclDefaulted);
if(bDaclPresent == TRUE)
{
if(pDacl == NULL)
{
LOG(L"A NULL discretionary access control list (DACL) found \nA NULL DACL implicitly allows all access to an object.\n");
}
else
{
LOG(L"A discretionary access control list (DACL) was found with Length = %d\n",pDacl->AclSize);
LOG(L"Number of Access Control Elements (ACE's): %d\n",pDacl->AceCount);
registryLogAces(pDacl);
}
}
else
{
LOG(L"No discretionary access control list (DACL) found \n");
}
LPTSTR StringSecurityDescriptor;
ULONG StringSecurityDescriptorLen;
ConvertSecurityDescriptorToStringSecurityDescriptor(pSecurityDescriptor,SDDL_REVISION_1,DACL_SECURITY_INFORMATION,
&StringSecurityDescriptor,&StringSecurityDescriptorLen);
LOG(L"%s\n",(const wchar_t*)StringSecurityDescriptor);
//parse info see http://msdn.microsoft.com/en-us/library/aa379570%28v=vs.85%29.aspx
LocalFree(StringSecurityDescriptor);
}
free(pSecurityDescriptor);
}
else
{
LOG_ERRORCODE(L"RegGetKeySecurity failed",err);
}
if(ERROR_SUCCESS != (err = RegCloseKey(hRegKey)))
{
LOG_ERRORCODE(L"RegCloseKey failed",err);
}
LOG_EXIT(iReturnCode);
return iReturnCode;
}
示例7: zabbix_log
/******************************************************************************
* *
* Function: zbx_win_getversion *
* *
* Purpose: get Windows version information *
* *
******************************************************************************/
const OSVERSIONINFOEX *zbx_win_getversion()
{
# define ZBX_REGKEY_VERSION "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
# define ZBX_REGVALUE_CURRENTVERSION "CurrentVersion"
# define ZBX_REGVALUE_CURRENTBUILDNUMBER "CurrentBuildNumber"
# define ZBX_REGVALUE_CSDVERSION "CSDVersion"
# define ZBX_REGKEY_PRODUCT "System\\CurrentControlSet\\Control\\ProductOptions"
# define ZBX_REGVALUE_PRODUCTTYPE "ProductType"
static OSVERSIONINFOEX vi = {sizeof(OSVERSIONINFOEX)};
OSVERSIONINFOEX *pvi = NULL;
HKEY h_key_registry = NULL;
wchar_t *key_value = NULL, *ptr;
if (0 != vi.dwMajorVersion)
return &vi;
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(ZBX_REGKEY_VERSION), 0, KEY_READ, &h_key_registry))
{
zabbix_log(LOG_LEVEL_DEBUG, "failed to open registry key '%s'", ZBX_REGKEY_VERSION);
goto out;
}
if (NULL == (key_value = read_registry_value(h_key_registry, TEXT(ZBX_REGVALUE_CURRENTVERSION))))
{
zabbix_log(LOG_LEVEL_DEBUG, "failed to read registry value '%s'", ZBX_REGVALUE_CURRENTVERSION);
goto out;
}
if (NULL != (ptr = wcschr(key_value, TEXT('.'))))
{
*ptr++ = L'\0';
vi.dwMinorVersion = _wtoi(ptr);
}
vi.dwMajorVersion = _wtoi(key_value);
zbx_free(key_value);
if (6 > vi.dwMajorVersion || 2 > vi.dwMinorVersion)
{
GetVersionEx((OSVERSIONINFO *)&vi);
}
else
{
if (NULL != (key_value = read_registry_value(h_key_registry, TEXT(ZBX_REGVALUE_CSDVERSION))))
{
wcscpy_s(vi.szCSDVersion, sizeof(vi.szCSDVersion) / sizeof(*vi.szCSDVersion), key_value);
zbx_free(key_value);
}
if (NULL == (key_value = read_registry_value(h_key_registry, TEXT(ZBX_REGVALUE_CURRENTBUILDNUMBER))))
{
zabbix_log(LOG_LEVEL_DEBUG, "failed to read registry value '%s'",
ZBX_REGVALUE_CURRENTBUILDNUMBER);
goto out;
}
vi.dwBuildNumber = _wtoi(key_value);
zbx_free(key_value);
RegCloseKey(h_key_registry);
h_key_registry = NULL;
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(ZBX_REGKEY_PRODUCT), 0, KEY_READ,
&h_key_registry))
{
zabbix_log(LOG_LEVEL_DEBUG, "failed to open registry key '%s'", ZBX_REGKEY_PRODUCT);
goto out;
}
if (NULL == (key_value = read_registry_value(h_key_registry, TEXT(ZBX_REGVALUE_PRODUCTTYPE))))
{
zabbix_log(LOG_LEVEL_DEBUG, "failed to read registry value '%s'", ZBX_REGVALUE_PRODUCTTYPE);
goto out;
}
if (0 == wcscmp(key_value, L"WinNT"))
vi.wProductType = 1;
else if (0 == wcscmp(key_value, L"LenmanNT"))
vi.wProductType = 2;
else if (0 == wcscmp(key_value, L"ServerNT"))
vi.wProductType = 3;
zbx_free(key_value);
vi.dwPlatformId = VER_PLATFORM_WIN32_NT;
}
pvi = &vi;
//.........这里部分代码省略.........
示例8: get_name
//.........这里部分代码省略.........
fprintf(stderr, "Opened %s\n", tun_name);
return tun_fd;
} else {
for (i = 0; i < TUN_MAX_TRY; i++) {
snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i);
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
fprintf(stderr, "Opened %s\n", tun_name);
snprintf(if_name, sizeof(if_name), "tun%d", i);
return tun_fd;
}
if (errno == ENOENT)
break;
}
warn("open_tun: Failed to open tunneling device");
}
return -1;
}
#endif /* !LINUX */
#else /* WINDOWS32 */
static void
get_device(char *device, int device_len, const char *wanted_dev)
{
LONG status;
HKEY adapter_key;
int index;
index = 0;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TAP_ADAPTER_KEY, 0, KEY_READ, &adapter_key);
if (status != ERROR_SUCCESS) {
warnx("Error opening registry key " TAP_ADAPTER_KEY );
return;
}
while (TRUE) {
char name[256];
char unit[256];
char component[256];
char cid_string[256] = KEY_COMPONENT_ID;
HKEY device_key;
DWORD datatype;
DWORD len;
/* Iterate through all adapter of this kind */
len = sizeof(name);
status = RegEnumKeyEx(adapter_key, index, name, &len, NULL, NULL, NULL, NULL);
if (status == ERROR_NO_MORE_ITEMS) {
break;
} else if (status != ERROR_SUCCESS) {
warnx("Error enumerating subkeys of registry key " TAP_ADAPTER_KEY );
break;
}
snprintf(unit, sizeof(unit), TAP_ADAPTER_KEY "\\%s", name);
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit, 0, KEY_READ, &device_key);
if (status != ERROR_SUCCESS) {
warnx("Error opening registry key %s", unit);
goto next;
}
示例9: platformGetFontPath
static String platformGetFontPath(const String& faceName) {
static const LPWSTR fontRegistryPath = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
HKEY hKey;
LONG result;
std::wstring wsFaceName(faceName.begin(), faceName.end());
// Open Windows font registry key
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fontRegistryPath, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS) {
throw std::runtime_error("Cant open registry!");
}
DWORD maxValueNameSize, maxValueDataSize;
result = RegQueryInfoKey(hKey, 0, 0, 0, 0, 0, 0, 0, &maxValueNameSize, &maxValueDataSize, 0, 0);
if (result != ERROR_SUCCESS) {
throw std::runtime_error("Cant query registry!");
}
DWORD valueIndex = 0;
LPWSTR valueName = new WCHAR[maxValueNameSize];
LPBYTE valueData = new BYTE[maxValueDataSize];
DWORD valueNameSize, valueDataSize, valueType;
std::wstring wsFontFile;
// Look for a matching font name
do {
wsFontFile.clear();
valueDataSize = maxValueDataSize;
valueNameSize = maxValueNameSize;
result = RegEnumValue(hKey, valueIndex, valueName, &valueNameSize, 0, &valueType, valueData, &valueDataSize);
valueIndex++;
if (result != ERROR_SUCCESS || valueType != REG_SZ) {
continue;
}
std::wstring wsValueName(valueName, valueNameSize);
// Found a match
if (_wcsnicmp(wsFaceName.c_str(), wsValueName.c_str(), wsFaceName.size()) == 0) {
wsFontFile.assign((LPWSTR)valueData, valueDataSize);
break;
}
} while (result != ERROR_NO_MORE_ITEMS);
delete[] valueName;
delete[] valueData;
RegCloseKey(hKey);
if (wsFontFile.empty()) {
throw std::runtime_error("Did not find matching font!");
}
// Build full font file path
WCHAR winDir[MAX_PATH];
GetWindowsDirectory(winDir, MAX_PATH);
std::wstringstream ss;
ss << winDir << "\\Fonts\\" << wsFontFile;
wsFontFile = ss.str();
return String(wsFontFile.begin(), wsFontFile.end());
}
示例10: fixMPEGinAVI
HRESULT TffdshowVideoInputPin::CheckMediaType(const CMediaType* mt)
{
if (mt->majortype != MEDIATYPE_Video && !(mt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK && supdvddec)) {
return VFW_E_TYPE_NOT_ACCEPTED;
}
if (mt->subtype == MEDIASUBTYPE_DVD_SUBPICTURE) {
return VFW_E_TYPE_NOT_ACCEPTED;
}
BITMAPINFOHEADER *hdr = NULL, hdr0;
if (mt->formattype == FORMAT_VideoInfo) {
VIDEOINFOHEADER *vih = (VIDEOINFOHEADER*)mt->pbFormat;
hdr = &vih->bmiHeader;
fixMPEGinAVI(hdr->biCompression);
} else if (mt->formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2 *vih2 = (VIDEOINFOHEADER2*)mt->pbFormat;
hdr = &vih2->bmiHeader;
fixMPEGinAVI(hdr->biCompression);
} else if (mt->formattype == FORMAT_MPEGVideo) {
MPEG1VIDEOINFO *mpeg1info = (MPEG1VIDEOINFO*)mt->pbFormat;
hdr = &(hdr0 = mpeg1info->hdr.bmiHeader);
hdr->biCompression = FOURCC_MPG1;
} else if (mt->formattype == FORMAT_MPEG2Video) {
MPEG2VIDEOINFO *mpeg2info = (MPEG2VIDEOINFO*)mt->pbFormat;
hdr = &(hdr0 = mpeg2info->hdr.bmiHeader);
if (hdr->biCompression == 0 || hdr->biCompression == 0x0038002d) {
if (mt->subtype == MEDIASUBTYPE_H264_TRANSPORT) {
hdr->biCompression = FOURCC_H264;
} else if (mt->subtype == MEDIASUBTYPE_AVC1 || mt->subtype == MEDIASUBTYPE_avc1 || mt->subtype == MEDIASUBTYPE_H264 || mt->subtype == MEDIASUBTYPE_h264 || mt->subtype == MEDIASUBTYPE_CCV1) {
hdr->biCompression = FOURCC_H264;
} else {
hdr->biCompression = FOURCC_MPG2;
}
}
} else if (mt->formattype == FORMAT_TheoraIll) {
sTheoraFormatBlock *oggFormat = (sTheoraFormatBlock*)mt->pbFormat;
hdr = &hdr0;
hdr->biWidth = oggFormat->width;
hdr->biHeight = oggFormat->height;
hdr->biCompression = FOURCC_THEO;
} else if (mt->formattype == FORMAT_RLTheora) {
hdr = &hdr0;
hdr->biCompression = FOURCC_THEO;
} else {
return VFW_E_TYPE_NOT_ACCEPTED;
}
char_t pomS[60];
DPRINTF(_l("TffdshowVideoInputPin::CheckMediaType: %s, %i, %i"), fourcc2str(hdr2fourcc(hdr, &mt->subtype), pomS, 60), hdr->biWidth, hdr->biHeight);
/* Information : WMP 11 and Media Center under Vista do not check for uncompressed format anymore, so no way to get
ffdshow raw video decoder for postprocessing on uncompressed.
So instead of saying "Media Type not supported", we says it is but only if there is an existing filter that can
take this format in charge, and then ffdshow will be plugged after this codec (plug is done by TffdshowDecVideo::ConnectCompatibleFilter). */
int res = getVideoCodecId(hdr, &mt->subtype, NULL);
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
ffstring exeFilename(fv->getExefilename());
exeFilename.ConvertToLowerCase();
if (res == 0 && pCompatibleFilter == NULL &&
fv->deci->getParam2(IDFF_alternateUncompressed) == 1 && // Enable WMP11 postprocessing
fv->deci->getParam2(IDFF_rawv) != 0 && // Raw video not on disabled
(exeFilename == _l("wmplayer.exe") ||
exeFilename == _l("ehshell.exe"))) { // Only WMP and Media Center are concerned
bool doPostProcessing = false;
if (osvi.dwMajorVersion > 5) { // OS >= VISTA
doPostProcessing = true;
} else if (osvi.dwMajorVersion == 5 // If OS=XP, check version of WMP
&& exeFilename == _l("ehshell.exe")) { // But only for Media Center
// Read WMP version from the aRegistry
HKEY hKey = NULL;
LONG regErr;
// Read WMP version from the following registry key
regErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _l("SOFTWARE\\Microsoft\\MediaPlayer\\Setup\\Installed Versions"), 0, KEY_READ, &hKey);
if (regErr != ERROR_SUCCESS) {
return res == AV_CODEC_ID_NONE ? VFW_E_TYPE_NOT_ACCEPTED : S_OK;
}
DWORD dwType;
BYTE buf[4096] = { '\0' }; // make it big enough for any kind of values
DWORD dwSize = sizeof(buf);
regErr = RegQueryValueEx(hKey, _T("wmplayer.exe"), 0, &dwType, buf, &dwSize);
if (hKey) {
RegCloseKey(hKey);
}
if (regErr != ERROR_SUCCESS || dwType != REG_BINARY) {
return res == AV_CODEC_ID_NONE ? VFW_E_TYPE_NOT_ACCEPTED : S_OK;
}
if (buf[2] >= 0x0b) { // Third byte is the major version number
doPostProcessing = true;
}
}
//.........这里部分代码省略.........
示例11: decompress_begin
LRESULT decompress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput)
{
BITMAPINFOHEADER * inhdr = &lpbiInput->bmiHeader;
xvid_gbl_init_t init;
xvid_gbl_info_t info;
xvid_dec_create_t create;
HKEY hKey;
if (init_dll(codec) != 0) return ICERR_ERROR;
memset(&init, 0, sizeof(init));
init.version = XVID_VERSION;
init.cpu_flags = codec->config.cpu;
init.debug = codec->config.debug;
codec->xvid_global_func(0, XVID_GBL_INIT, &init, NULL);
memset(&info, 0, sizeof(info));
info.version = XVID_VERSION;
codec->xvid_global_func(0, XVID_GBL_INFO, &info, NULL);
memset(&create, 0, sizeof(create));
create.version = XVID_VERSION;
create.width = lpbiInput->bmiHeader.biWidth;
create.height = lpbiInput->bmiHeader.biHeight;
create.fourcc = inhdr->biCompression;
/* Decoder threads */
if (codec->config.cpu & XVID_CPU_FORCE)
create.num_threads = codec->config.num_threads;
else
create.num_threads = info.num_threads; /* Autodetect */
switch(codec->xvid_decore_func(0, XVID_DEC_CREATE, &create, NULL))
{
case XVID_ERR_FAIL :
return ICERR_ERROR;
case XVID_ERR_MEMORY :
return ICERR_MEMORY;
case XVID_ERR_FORMAT :
return ICERR_BADFORMAT;
case XVID_ERR_VERSION :
return ICERR_UNSUPPORTED;
}
codec->dhandle = create.handle;
RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);
REG_GET_N("Brightness", pp_brightness, 0);
REG_GET_N("Deblock_Y", pp_dy, 0);
REG_GET_N("Deblock_UV", pp_duv, 0);
REG_GET_N("Dering_Y", pp_dry, 0);
REG_GET_N("Dering_UV", pp_druv, 0);
REG_GET_N("FilmEffect", pp_fe, 0);
RegCloseKey(hKey);
return ICERR_OK;
}
示例12: strncpy
static char *DigiCrypt_GetFirstAllowedCSPNameNew(void)
{
char *psRes = NULL;
HKEY hKey = NULL;
LONG lRet=0;
DWORD dwIndex = 0;
BOOL fRes;
char sProvName[dSTRING_ITEM_LEN+1];
char sKeyNameBuf[dSTRING_ITEM_LEN+1];
HCRYPTPROV hProvide = 0;
DWORD dwBufLen;
FILETIME oTime;
//char buff[200];
BYTE pbData[dNAME_ITEM_LEN+1];
DWORD cbData=dNAME_ITEM_LEN+1;
//
DWORD dwProvType;
strncpy(sKeyNameBuf, psData_CSP_Path, sizeof(sKeyNameBuf));
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,sKeyNameBuf,0, KEY_READ, &hKey);
while (lRet == ERROR_SUCCESS) {
dwBufLen = dSTRING_ITEM_LEN;
lRet = RegEnumKeyEx(hKey,dwIndex,sProvName,&dwBufLen,NULL,NULL,0,&oTime);
if (lRet == ERROR_SUCCESS) {
if (lstrcmp(sProvName,psData_Ignore_CSP_Name) != 0) {
dwProvType = DigiCrypt_FindContext_GetCSPType(sProvName);
LOG("CSP %s",sProvName);
//printf("%s :",sProvName);
if ((lstrcmp(sProvName,psData_Extra_CSP_Name) != 0) && (lstrcmp(sProvName,"Belgium Identity Card CSP")!=0)) {
//fRes = OpenProvider(&hProvide, sProvName, CRYPT_SILENT);
fRes = CryptAcquireContext(&hProvide,NULL,sProvName,dwProvType, CRYPT_SILENT);
fRes=CryptGetProvParam(hProvide, PP_ENUMCONTAINERS, pbData, &cbData,CRYPT_FIRST);
// printf("X\n");
} else {
//fRes = OpenProvider(&hProvide, sProvName, CRYPT_VERIFYCONTEXT);
//fRes = CryptAcquireContext(&hProvide,"SetCARDKeyContainer",sProvName,dwProvType, CRYPT_SILENT);
fRes = CryptAcquireContext(&hProvide,NULL,sProvName,dwProvType, CRYPT_VERIFYCONTEXT);
if (fRes == TRUE) {
//the extra csp might give wrong answer. We should ask from provider, why.
//The following is the work-around -- try to lookup key container from the card.
//if the result is negative this is a not the csp what is needed.
fRes=CryptGetProvParam(hProvide, PP_ENUMCONTAINERS, pbData, &cbData,CRYPT_FIRST);
if (fRes == TRUE)
fRes=CryptAcquireContext(&hProvide,(char*)pbData,sProvName,dwProvType, CRYPT_SILENT);
}
}
//printf("fRes: %x\n",GetLastError());
if (fRes == TRUE) { // && dwProvType == 2)
// printf("OK %d %s\n",cbData, pbData);
//set global values
LOG("CSP %s accepted",sProvName);
//is it hardware token?
cbData=dNAME_ITEM_LEN+1;
if (CryptGetProvParam(hProvide, PP_IMPTYPE, pbData, &cbData, 0)) {
//printf("implementat: %d\n",pbData[0]);
if((pbData[0] & 1)) // hardware token
{
strncpy(oG_sCSPName, sProvName, sizeof(oG_sCSPName));
//CryptReleaseContext(hProvide, 0);
psRes = oG_sCSPName;
break;
}
}
}
}
}
//hProvide = 0;
CryptReleaseContext(hProvide, 0);
dwIndex++;
}
if (hKey != NULL)
RegCloseKey(hKey);
return(psRes);
}
示例13: EnumImageHijack
BOOL EnumImageHijack( AUTORUN_CALLBACK pfnCallback, LPVOID lpParam )
{
CHKey hKey;
DWORD dwResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options",
0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, (PHKEY)&hKey );
if(ERROR_SUCCESS != dwResult ) {
SetLastError( dwResult );
return FALSE;
}
//查询子键数量
DWORD cSubKey = 0;
dwResult = RegQueryInfoKey( hKey.GetHandle(), NULL, NULL, 0, &cSubKey, NULL,NULL, NULL, NULL, NULL, NULL, NULL );
if( ERROR_SUCCESS != dwResult ) {
SetLastError( dwResult );
return FALSE;
}
LPCTSTR lpszSystemDir = getenv( "SystemRoot" );
if( lpszSystemDir == NULL )
return FALSE;
for( DWORD i=0; i < cSubKey; i++ ) {
AUTORUN_ITEM Item = {0};
dwResult = RegEnumKey( hKey.GetHandle(), i, Item.Name, sizeof( Item.Name ) );
if( ERROR_SUCCESS != dwResult ) {
SetLastError( dwResult );
continue;
}
//打开子键
CHKey hSubKey ;
dwResult = RegOpenKeyEx( hKey.GetHandle(), Item.Name, 0, KEY_QUERY_VALUE, (PHKEY)&hSubKey );
if( ERROR_SUCCESS != dwResult ){
SetLastError( dwResult );
continue;
}
char Buffer[512] = {0};
DWORD cbSize = sizeof( Buffer );
dwResult = RegQueryValueEx( hSubKey.GetHandle(), "Debugger", NULL, NULL, (PUCHAR)Buffer, &cbSize );
if( dwResult != ERROR_SUCCESS ) {
SetLastError( dwResult );
continue;
}
strncpy( Item.ImagePath, lpszSystemDir, sizeof( Item.ImagePath ) - 1 );
PathAddBackslash( Item.ImagePath );
strncat( Item.ImagePath, "System32\\", sizeof( Item.ImagePath ) - strlen( Item.ImagePath ) - 1 );
strncat( Item.ImagePath, Buffer, sizeof( Item.ImagePath ) - strlen( Item.ImagePath ) - 1 );
//去掉删除
PathRemoveArgs( Item.ImagePath );
PathAddExtension( Item.ImagePath, ".exe" );
if( !pfnCallback( AUTORUN_IMAGE_HIJACK, &Item, lpParam ) ) {
SetLastError( ERROR_CANCELLED );
return FALSE;
}
}
return TRUE;
}
示例14: findJreInfoFromRegistry
/*----------------------------------------------------------------------
Get info about JRE from registry.
----------------------------------------------------------------------*/
static int findJreInfoFromRegistry(char *path, char *args) {
INT i;
HKEY hKey; /* Key handle of NetShell */
CHAR ValueName[MAX_PATH]; /* Name of value. */
DWORD cbValueName; /* Size of value name. */
DWORD dwType; /* Type of data. */
CHAR bData[MAX_PATH]; /* Data buffer. */
DWORD cbData; /* Size of data buffer. */
DWORD retCode;
CHAR *Param;
BOOL found = FALSE; /* We have found info in the registry */
/* Open the key for jre and get info about it. */
retCode = RegOpenKeyEx(hKeyRoot, SubKey, 0, KEY_EXECUTE, &hKey);
if (retCode != ERROR_SUCCESS) {
DPRINT(("stub: RegOpenKeyEx error for hKey = %d\n",
retCode));
return FALSE;
}
for (i = 0; retCode == ERROR_SUCCESS; i++) {
bData[0] = '\0';
ValueName[0] = '\0';
cbData = MAX_PATH;
cbValueName = MAX_PATH;
/* Enumerate the key values. */
retCode = RegEnumValue(hKey, i, ValueName, &cbValueName,
NULL, &dwType, bData, &cbData);
if (retCode != ERROR_SUCCESS) {
if (dwType < REG_FULL_RESOURCE_DESCRIPTOR &&
retCode != ERROR_NO_MORE_ITEMS) {
DPRINT(("stub: ERROR, RegEnumValue = %d cbData = %d line %d\n"
, retCode, cbData, __LINE__));
return FALSE;
}
}
DPRINT(("stub.findJreInfo...: i=%d, ValueName=%s, cbValueName=%d, dwType=%d,\n\t bData=%s, cbData=%d; retCode=%d\n", i, ValueName, cbValueName, dwType, bData, cbData, retCode));
/* Process the value accordingly. */
Param = _strlwr(ValueName);
if(!strcmp("javahome", Param)) {
DPRINT(("stub.findJreInfo...: Setting path and args to %s\n",bData));
strcat(path, bData);
strcat(args, bData);
found = TRUE;
}
if(!strcmp("microversion", Param)) {
DPRINT(("stub.findJreInfo...: found JRE 1.1.%s\n",bData));
if(atoi(bData) < 6) {
CHAR title[TITLELEN];
CHAR msg[MSGLEN];
LoadString(NULL, IDS_OLD_JRE_TITLE, title, TITLELEN);
LoadString(NULL, IDS_OLD_JRE_MSG, msg, MSGLEN);
MessageBox(NULL, msg, title,
MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND);
DPRINT(("stub: version of jre is too old"));
return FALSE;
}
}
}
DPRINT(("stub.findJreInfo...: done, found=%d",found));
return found;
}
示例15: GetPortNumXP2000Vista
// query com ports on:
// Windows 2000 - XP - Vista - 7
//
int GetPortNumXP2000Vista(WORD vid, WORD pid, char* ser)
{
//Variables used for Registry access
HKEY tmpKey, tmpSubKey, tmpPortKey;
CString portKeyString;
DWORD valtype;
char* portString;
DWORD length = 100;
portString = new char[101];
//Set portnum to -1, so if there is an error we will
//know by returning a negative port value
int portNum = -1;
// Open keys to get to the key where the port number is located. This key is:
// HKLM\System\CurrentControlSet\Enum\USB\Vid_xxxx&Pid_yyyy&Mi_00\zzzz_00\DeviceParameters\PortName
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\", 0, KEY_READ, &tmpKey))
{
if (ERROR_SUCCESS == RegOpenKey(tmpKey, "Enum\\USB\\", &tmpSubKey))
{
//Loop through and replace spaces for WinXP2000Vista
int i = 0;
while (ser[i] != '\0')
{
if (ser[i] == 0x20)
ser[i] = '_';
i++;
}
//The portkey string should look like this
//"Vid_XXXX&Pid_XXXX&MI_00\\XXXX_00" where the XXXX's are Vid, Pid and serial string - version less than 5.0
//"Vid_XXXX&Pid_XXXX\\XXXX" where the XXXX's are Vid, Pid and serial string - version greater than or equal to 5.0
portKeyString.Format("Vid_%04x&Pid_%04x&Mi_00\\%s_00\\Device Parameters\\", vid, pid, ser);
//If the portkey string is in the registry, then go ahead and open the portname
if (ERROR_SUCCESS == RegOpenKeyEx(tmpSubKey, portKeyString, 0, KEY_READ, &tmpPortKey))
{
if (ERROR_SUCCESS == RegQueryValueEx(tmpPortKey, "PortName", NULL, &valtype, (unsigned char *)portString, &length))
{
// When we obtain this key, it will be in string format of
// "COMXX" where XX is the port. Simply make the first three
// elements of the string 0, and call the atoi function to obtain
// the number of the port.
portString[0] = '0';
portString[1] = '0';
portString[2] = '0';
portNum = atoi(portString);
}
//Make sure to close all open keys for cleanup
RegCloseKey(tmpPortKey);
}
else
{
portKeyString.Format("Vid_%04x&Pid_%04x\\%s\\Device Parameters\\", vid, pid, ser);
//If the portkey string is in the registry, then go ahead and open the portname
if (ERROR_SUCCESS == RegOpenKeyEx(tmpSubKey, portKeyString, 0, KEY_READ, &tmpPortKey))
{
if (ERROR_SUCCESS == RegQueryValueEx(tmpPortKey, "PortName", NULL, &valtype, (unsigned char *)portString, &length))
{
// When we obtain this key, it will be in string format of
// "COMXX" where XX is the port. Simply make the first three
// elements of the string 0, and call the atoi function to obtain
// the number of the port.
portString[0] = '0';
portString[1] = '0';
portString[2] = '0';
portNum = atoi(portString);
}
//Make sure to close all open keys for cleanup
RegCloseKey(tmpPortKey);
}
}
RegCloseKey(tmpSubKey);
}
RegCloseKey(tmpKey);
}
RegCloseKey(HKEY_LOCAL_MACHINE);
delete portString;
// Return the number of the port the device is connected too
return portNum;
}