Exemple #1
1
bool IsDotNet35()
{
	bool ret = false;
	int lpType = 0;
	HKEY key;
	DWORD dwValSize = 50;
	LONG regret;
	LPTSTR lpValname = new TCHAR[50];
	regret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\.NETCompactFramework"), 0, KEY_QUERY_VALUE, &key);
	if (regret == 0)
	{
		int i = 0;
		while((regret = RegEnumValue(key, i++, lpValname, &dwValSize, NULL,NULL, NULL, NULL)) == 0)
		{
			lpValname[1] = 0;
			lpValname[3] = 0;
			int majVer = _ttoi(&lpValname[0]);
			int minVer = _ttoi(&lpValname[2]);
			if(majVer > 3 || (majVer == 3 && minVer >= 5))
			{
				ret = true;
				break;
			}
		}
		RegCloseKey(key);
	}
	return ret;
}
Exemple #2
0
// On input dwValueNameSize is size in characters of buffer pointed by pchValueNameBuffer
// On output dwValueNameSize contains number of characters stored in buffer
LONG CRegistryKey::GetNextValue(DWORD *pdwNameActualSize, DWORD *pdwDataActualSize)
{
  if (!m_hKey)
    return ERROR_NO_MORE_ITEMS; // the root key abstraction has only subkeys (hives)

	DWORD dwValueNameBufferSize = m_dwValueNameBufferSize;
	DWORD dwValueDataBufferSize = m_dwValueDataBufferSize;
  LONG nError = RegEnumValue(m_hKey,
                            m_dwCurrentValueIndex,
                            m_pszValueNameBuffer,
                            &dwValueNameBufferSize,
                            NULL,
                            m_pdwType,
                            m_pbValueDataBuffer,
                            &dwValueDataBufferSize);

  if (pdwNameActualSize)
    *pdwNameActualSize = dwValueNameBufferSize;

  if (pdwDataActualSize)
    *pdwDataActualSize = dwValueDataBufferSize;

	m_dwCurrentValueIndex++;
	return nError;
}
Exemple #3
0
bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const
{
  wxASSERT( IsOpened() );

  // are we already at the end of enumeration?
  if ( lIndex == -1 )
    return false;

    wxChar  szValueName[1024];                  // @@ use RegQueryInfoKey...
    DWORD dwValueLen = WXSIZEOF(szValueName);

    m_dwLastError = RegEnumValue((HKEY) m_hKey, lIndex++,
                                 szValueName, &dwValueLen,
                                 RESERVED,
                                 NULL,            // [out] type
                                 NULL,            // [out] buffer for value
                                 NULL);           // [i/o]  it's length

    if ( m_dwLastError != ERROR_SUCCESS ) {
      if ( m_dwLastError == ERROR_NO_MORE_ITEMS ) {
        m_dwLastError = ERROR_SUCCESS;
        lIndex = -1;
      }
      else {
        wxLogSysError(m_dwLastError, _("Can't enumerate values of key '%s'"),
                      GetName().c_str());
      }

      return false;
    }

    strValueName = szValueName;

  return true;
}
void UsbDeviceList::FetchInterfaceFilters(LPCUSB_FUNCS lpUsbFuncs,
																					LPCWSTR szUniqueDriverId)
{
	HKEY key;
	LONG result;
	DWORD numValues = 0, maxNameLen = 0, maxValueLen = 0;
	DWORD valueType;
	PWCHAR nameBuf;
	PBYTE valueBuf;

	// We do not support dynamic updating of the filter list
	if (mNumInterfaceFilters > 0) {
		return;
	}
	
	key = lpUsbFuncs->lpOpenClientRegistyKey(szUniqueDriverId);
	if (!key) {
		ERROR_MSG((TEXT("USBKWrapperDrv!UsbDeviceList::FetchInterfaceFilters() - Failed to open client registry key\r\n")));
		return;
	}

	result = RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, 
		&numValues, &maxNameLen, &maxValueLen, NULL, NULL);
	if (result != ERROR_SUCCESS) {
		ERROR_MSG((TEXT("USBKWrapperDrv!UsbDeviceList::FetchInterfaceFilters() - Failed to query key info: error %i\r\n"), result));
		RegCloseKey(key);
		return;
	}

	nameBuf = new (std::nothrow) WCHAR[maxNameLen+1];
	valueBuf = new (std::nothrow) BYTE[maxValueLen];

	if (!nameBuf || !valueBuf) {
		ERROR_MSG((TEXT("USBKWrapperDrv!UsbDeviceList::FetchInterfaceFilters() - Out of memory allocating buffers\r\n")));		
		delete[] nameBuf;
		delete[] valueBuf;
		RegCloseKey(key);
		return;
	}

	for (DWORD index = 0; index < numValues && result == ERROR_SUCCESS; index++) {
		DWORD nameBufSize = maxNameLen + 1;
		DWORD valueBufSize = maxValueLen;
		result = RegEnumValue(key, index, nameBuf, &nameBufSize, NULL, &valueType, 
			valueBuf, &valueBufSize);

		if (result == ERROR_SUCCESS) {
			// Pay attention only to unicode strings (REG_SZ) whose name has the 
			// InterfaceFilter_ prefix
			if (nameBufSize > 16 && wcsncmp(nameBuf, TEXT("InterfaceFilter_"), 16) == 0 && 
				valueType == REG_SZ) {
				AddInterfaceFilter(&nameBuf[16], (LPCWSTR) valueBuf);
			}
		}
	}

	delete[] nameBuf;
	delete[] valueBuf;
	RegCloseKey(key);
}
Exemple #5
0
// CComSetDlg 消息处理程序
INT_PTR		CComSetDlg::GetSerialPort(CStringArray &arrCom)
{
	arrCom.RemoveAll();
	HKEY	hkey;
	LONG32	lRes = RegOpenKeyEx(
		HKEY_LOCAL_MACHINE,_T("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
		NULL,KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS|KEY_READ,&hkey);
	if (lRes == ERROR_SUCCESS)
	{
		TCHAR	tchKey[MAX_PATH];
		TCHAR	tchValue[20];
		DWORD	dwIndex = 0;
		DWORD	dwType = REG_SZ;
		while(lRes == ERROR_SUCCESS)
		{
			DWORD	dwCnt = MAX_PATH;
			DWORD	dwVCount = 20;
			lRes = RegEnumValue(hkey,dwIndex++,tchKey,&dwCnt,NULL,
				&dwType,(LPBYTE)tchValue,&dwVCount);
			if (lRes == ERROR_SUCCESS)
			{
				if(dwVCount >0 && dwCnt >0)
					arrCom.Add(tchValue);
			}
		}
	}
	RegCloseKey(hkey);
	return arrCom.GetSize();
}
Exemple #6
0
// 查找串口
void CPMSRSet::FindComPort()
{
	HKEY   hKey;

	st_CommPara.usCommNum = 0;	// 串口数量

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
	{
		TCHAR       szPortName[256], szComName[256];
		DWORD       dwLong, dwSize;
		int         nCount = 0;
		CComboBox*  pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);

		pCombo->ResetContent();
		while (true)
		{
			dwLong = dwSize = 256;
			if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
				break;

			pCombo->InsertString(nCount, szComName);
			nCount++;
			st_CommPara.usCommNum++;
		}
		RegCloseKey(hKey);
		pCombo->SetCurSel(0);
	}

}
Exemple #7
0
static krb5_error_code
parse_reg_values(krb5_context context,
                 HKEY key,
                 krb5_config_section ** parent)
{
    DWORD index;
    LONG  rcode;

    for (index = 0; ; index ++) {
        char    name[16385];
        DWORD   cch = sizeof(name)/sizeof(name[0]);
        DWORD   type;
        DWORD   cbdata = 0;
        krb5_error_code code;

        rcode = RegEnumValue(key, index, name, &cch, NULL,
                             &type, NULL, &cbdata);
        if (rcode != ERROR_SUCCESS)
            break;

        if (cbdata == 0)
            continue;

        code = parse_reg_value(context, key, name, type, cbdata, parent);
        if (code != 0)
            return code;
    }

    return 0;
}
Exemple #8
0
INT
GetLayoutCount(LPTSTR szLang)
{
    HKEY hKey;
    TCHAR szLayoutID[3 + 1], szPreload[CCH_LAYOUT_ID + 1], szLOLang[MAX_PATH];
    DWORD dwIndex = 0, dwType, dwSize;
    UINT Count = 0, i, j;

    if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"),
                     0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    {
        dwSize = sizeof(szLayoutID);

        while (RegEnumValue(hKey, dwIndex, szLayoutID, &dwSize, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS)
        {
            dwSize = sizeof(szPreload);
            RegQueryValueEx(hKey, szLayoutID, NULL, NULL, (LPBYTE)szPreload, &dwSize);

            for (i = 4, j = 0; i < _tcslen(szPreload)+1; i++, j++)
                szLOLang[j] = szPreload[i];

            if (_tcscmp(szLOLang, szLang) == 0) Count += 1;

            dwSize = sizeof(szLayoutID);
            dwIndex++;
        }

        RegCloseKey(hKey);
    }

    return Count;
}
void RegistryKeys::GetSupplyIntervalMultiplier(int *multi)
{
	// If this is the first time running, or the key doesn't exist, return default values
	*multi=6;

	HKEY hKey;
	char subkey[]="Software\\MediaDefender\\WinMx\\Supply Interval Multiplier";

	if(RegOpenKeyEx(HKEY_CURRENT_USER,subkey,0,KEY_READ,&hKey)==ERROR_SUCCESS)
	{
		char szName[1024];
		DWORD cbName=sizeof(szName)/sizeof(szName[0]);
		DWORD dwType;

		int val;
		DWORD cbData=sizeof(int);

		DWORD index=0;
		while(RegEnumValue(hKey,index,szName,&cbName,NULL,&dwType,(unsigned char *)&val,&cbData)==ERROR_SUCCESS)
		{
			if(strcmp(szName,"Multiplier")==0)
			{
				*multi=val;
			}
			cbName=sizeof(szName)/sizeof(szName[0]);	// reset the size
			index++;			
		}
	}

	RegCloseKey(hKey);
}
Exemple #10
0
int main()
{
	unsigned long com_nb;
	char reg_key[CHAR_LEN]; 
	char reg_val[CHAR_LEN]; 
	long ret;
	unsigned long reg_index = 0; 
	unsigned long len_key;
	unsigned long len_val; 
	unsigned long type;
	
	HKEY hkey; 
	char  *key_str="HARDWARE\\DEVICEMAP\\SERIALCOMM\\";

	len_key = sizeof(reg_key); 
	len_val = sizeof(reg_val);

	//long ret0 = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_Set, 0, KEY_READ, &hKey)); 
	if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, key_str, 0, KEY_READ, &hkey) == ERROR_SUCCESS) {
		printf("NODE\t\t                       PORTNUM \t\t       CYGWIN\n\n");
		do {
			ret = RegEnumValue(hkey, reg_index++, reg_key, &len_key, NULL, &type, reg_val, &len_val);
			if((ret == ERROR_SUCCESS) || (ret == ERROR_MORE_DATA)) { 
				com_nb = atoi(strtok(reg_val, "COM"));
				printf("%-30s \t\t %5s \t\t   /dev/ttyS%d\n", reg_key, reg_val, com_nb - 1);
			}

			len_key = sizeof(reg_key); 
			len_val = sizeof(reg_val); 
		} while ((ret == ERROR_SUCCESS) || (ret == ERROR_MORE_DATA)); 
		RegCloseKey(hkey); 
	} else {
		printf("Can not open HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM\\\n");
	}
}
Exemple #11
0
 /*
  * Enumeration
  */
  bool EnumValues(TSTRING &tsNameOut, BYTE *pValueData, DWORD_PTR dwDataSize, 
                  DWORD_PTR dwType = REG_SZ)
  {

    bool r                = false;
    static DWORD dwIndex  = 0UL;
    LONG lRet             = ERROR_SUCCESS;
    TCHAR szBuf[16383]    = {0};
    DWORD dwNameSize      = 16383;

    lRet = RegEnumValue(m_hKey,
                        dwIndex++,
                        szBuf,
                        &dwNameSize,
                        NULL,
                        &dwType,
                        pValueData,
                        &dwDataSize);

    if (ERROR_SUCCESS == lRet) {

      tsNameOut = szBuf;
      r         = true;

    } else if (ERROR_NO_MORE_ITEMS == lRet) {

      tsNameOut = _T("");
      dwIndex   = 0UL;
      ZeroMemory(pValueData, dwDataSize);
      
    }

    return r;
  }
Exemple #12
0
static LIST* get_value_names(HKEY key, char const* path)
{
    LIST* result = 0;

    if ( ERROR_SUCCESS == RegOpenKeyEx(key, path, 0, KEY_QUERY_VALUE, &key) )
    {
        char name[MAX_REGISTRY_VALUENAME_LENGTH];
        DWORD name_size = sizeof(name);
        DWORD index;

        for ( index = 0;
              ERROR_SUCCESS == RegEnumValue(
                  key, index, name, &name_size, 0, 0, 0, 0);
              ++index,
              name_size = sizeof(name)
        )
        {
            name[name_size] = 0;
            result = list_append(result, list_new(0, newstr(name)));
        }

        RegCloseKey(key);
    }

    return result;
}
Exemple #13
0
PUBLIC MprList *mprListRegistry(cchar *key)
{
    HKEY        top, h;
    wchar       name[ME_MAX_PATH];
    MprList     *list;
    int         index, size;

    assert(key && *key);

    /*
        Get the registry hive
     */
    if ((key = getHive(key, &top)) == 0) {
        return 0;
    }
    if (RegOpenKeyEx(top, wide(key), 0, KEY_READ, &h) != ERROR_SUCCESS) {
        return 0;
    }
    list = mprCreateList(0, 0);
    index = 0;
    while (1) {
        size = sizeof(name) / sizeof(wchar);
        if (RegEnumValue(h, index, name, &size, 0, NULL, NULL, NULL) != ERROR_SUCCESS) {
            break;
        }
        mprAddItem(list, sclone(multi(name)));
        index++;
    }
    RegCloseKey(h);
    return list;
}
void CDownloads::PurgeDeletes()
{
	CStringList pRemove;
	HKEY hKey = NULL;
	
	if ( ERROR_SUCCESS != RegOpenKeyEx( HKEY_CURRENT_USER,
		_T("Software\\Shareaza\\Shareaza\\Delete"), 0, KEY_ALL_ACCESS, &hKey ) ) return;
	
	for ( DWORD nIndex = 0 ; nIndex < 1000 ; nIndex ++ )
	{
		DWORD nPath = MAX_PATH*2;
		TCHAR szPath[MAX_PATH*2];
		
		if ( ERROR_SUCCESS != RegEnumValue( hKey, nIndex, szPath, &nPath, NULL,
			NULL, NULL, NULL ) ) break;
		
		if ( GetFileAttributes( szPath ) == 0xFFFFFFFF || DeleteFile( szPath ) )
		{
			pRemove.AddTail( szPath );
		}
	}
	
	while ( ! pRemove.IsEmpty() )
	{
		RegDeleteValue( hKey, pRemove.RemoveHead() );
	}
	
	RegCloseKey( hKey );
}
// Read the data from the registry filling in the data areas.
int CRegistryData::ReadRegistry(void)
{
	HKEY  hKey = 0;

	LONG lRetVal = RegOpenKeyEx (HKEY_LOCAL_MACHINE, m_OposRootKey, 0, KEY_READ, &hKey);
	if (lRetVal == ERROR_SUCCESS) {
		DWORD  dwIndex = 0;
		DWORD  dwType;

		do {
			wchar_t  wsValueName[128] = {0};
			BYTE     wsValueValue[256] = {0};

			DWORD  dwValueNameSize = 124, dwValueValueSize = sizeof(wsValueValue);

			lRetVal = RegEnumValue (hKey, dwIndex, wsValueName, &dwValueNameSize, NULL, &dwType, wsValueValue, &dwValueValueSize);
			if (dwValueNameSize > 0 && lRetVal == ERROR_SUCCESS) {
				wsValueName[dwValueNameSize] = 0;
				wsValueValue[dwValueValueSize] = wsValueValue[dwValueValueSize+1] = 0;
				m_RegistryData.Add(std::wstring(wsValueName), std::wstring((wchar_t *)wsValueValue));
			}
			dwIndex++;
		} while (lRetVal == ERROR_SUCCESS);

		lRetVal = RegCloseKey (hKey);
	}

	return 0;
}
Exemple #16
0
// Enumerate a key or a value.  Returns a string option containing NONE if
// no key/value could be found or SOME s where s is the name of the key/value.
static Handle enumerateRegistry(TaskData *taskData, Handle args, HKEY hkey, BOOL isKey)
{
    DWORD num = get_C_unsigned(taskData, DEREFWORDHANDLE(args)->Get(1));
    LONG lRes;
    TCHAR keyName[MAX_PATH];
    DWORD dwLength = sizeof(keyName)/sizeof(keyName[0]);
    Handle result, resVal;
    if (isKey)
    {
        FILETIME ftMod;
        lRes = RegEnumKeyEx(hkey, num, keyName, &dwLength, NULL, NULL, NULL, &ftMod);
        if (lRes != ERROR_SUCCESS && lRes != ERROR_NO_MORE_ITEMS)
            raise_syscall(taskData, "RegEnumKeyEx failed", -lRes);
    }
    else
    {
        lRes = RegEnumValue(hkey, num, keyName, &dwLength, NULL, NULL, NULL, NULL);
        if (lRes != ERROR_SUCCESS && lRes != ERROR_NO_MORE_ITEMS)
            raise_syscall(taskData, "RegEnumValue failed", -lRes);
    }
    if (lRes == ERROR_NO_MORE_ITEMS)
        return SAVE(NONE_VALUE); /* NONE. */
    resVal = SAVE(C_string_to_Poly(taskData, keyName));
    result = alloc_and_save(taskData, 1);
    DEREFHANDLE(result)->Set(0, DEREFWORDHANDLE(resVal));
    return result;
}
Exemple #17
0
//从注册表中获得hivelist
bool ntreg_init_getHivelist(map<wstring, wstring> &map_){
	//
	DWORD dwIndex = 0;
	HKEY hKey = NULL;
	TCHAR tcName[MAX_PATH] = { 0 };
	DWORD dwSize = MAX_PATH;
	DWORD dwType = 0;
	TCHAR tcValue[MAX_PATH] = { 0 };
	DWORD dwValueSize = MAX_PATH;

	//
	if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,L"SYSTEM\\CurrentControlSet\\Control\\hivelist",0,KEY_READ,&hKey) != ERROR_SUCCESS) 
	{
		//
		return false ;
	}

	//
	while(RegEnumValue(hKey,dwIndex,tcName,&dwSize,0,&dwType,(LPBYTE)tcValue,&dwValueSize) != ERROR_NO_MORE_ITEMS)
	{
		//
		map_.insert(map<wstring, wstring>::value_type(tcName,tcValue));

		//
		dwSize = MAX_PATH;
		dwValueSize = MAX_PATH;
		dwIndex++;
	}

	//
	RegCloseKey(hKey);
	return true ;
}
Exemple #18
0
bool RegUtils::DeleteKeyValues(const HKEY& hSourceKey )
{
	bool bRet = true;

	TCHAR	szValueName[MAX_PATH];
	DWORD	dwValueNameSize = MAX_PATH;

	DWORD retcode = ERROR_SUCCESS;
	while ( retcode == ERROR_SUCCESS )
	{
		dwValueNameSize = MAX_PATH;
		ZeroMemory(szValueName, MAX_PATH);

		retcode = RegEnumValue(hSourceKey, 0, szValueName, &dwValueNameSize, NULL, NULL, NULL, NULL);
		if (retcode == ERROR_SUCCESS)
		{
			long lSetVal = RegDeleteValue( hSourceKey, szValueName );
			if (lSetVal != ERROR_SUCCESS)
			{
				CStdString sErr;
				sErr.Format(_T("Failed to delete value '%s', error %d"), szValueName, lSetVal);
				LOG_WS_ERROR(sErr.c_str());
			}
		}
		else if (retcode != ERROR_NO_MORE_ITEMS)
		{
			CStdString sErr;
			sErr.Format(_T("Failed to enumerate source values %s, error %d"), szValueName, retcode);
			LOG_WS_ERROR(sErr.c_str());
			bRet = false;
		}
	}

	return bRet;
}
Exemple #19
0
int EnumRegKey( const char *key, void (*save)( char *name, char *val, void *data ), void *data )
{

	HKEY hKey = OpenRegKey( key );
	int res = ERROR_SUCCESS;
	char name[MAX_PATH], val[MAX_PATH];

	if( !hKey )
		hKey = CreateRegKey( key );

	if( !hKey )
		return 0;

	for( int index = 0; res == ERROR_SUCCESS; index++ ) {

		unsigned long sz1, sz2, type;

		sz1 = sz2 = MAX_PATH;

		res = RegEnumValue( hKey, index, name, &sz1, NULL, &type, (BYTE*)val, &sz2 );
		if( res == ERROR_SUCCESS && type == REG_SZ ) {
			save(name, val, data);
		}
	}

	RegCloseKey(hKey);
	return 1;
}
Exemple #20
0
std::vector<tstring> RegKey::getValues(void)
{
	if(m_hKeyHandle == NULL) {
		xCeptionSmartUtilities x(  "No open reg key!" );
		throw x;
	}
	if(!(m_pAccess & KEY_ENUMERATE_SUB_KEYS)) {
		xCeptionSmartUtilities x("You need to have KEY_ENUMERATE_SUB_KEYS access rights!" );
		throw x;
	}

	DWORD cbName;
	LONG lResult;
	std::vector<tstring> v;
	if(REGKEYINFO.cValues) {
		TCHAR* tmp = (TCHAR*)malloc((REGKEYINFO.cchMaxValue + 1) * sizeof(TCHAR));
		for(int i=0; i<REGKEYINFO.cValues; i++) {
			memset(tmp,0,(REGKEYINFO.cchMaxValue + 1) * sizeof(TCHAR));
			cbName = 16383;
			lResult = RegEnumValue(m_hKeyHandle, i,
                 tmp, 
                 &cbName, 
                 NULL, 
                 NULL, 
                 NULL, 
                 NULL); 
			if(lResult == ERROR_SUCCESS) v.push_back(tmp);
		}
		free(tmp);
	}
	return v;
}
Exemple #21
0
/* walks to the first value */
bool
RegFindFirstValue (HKEY hKey, LPCTSTR *ppszValue, RegVal *pValData)
{
  if (RegQueryInfoKey (hKey, nullptr, nullptr, 0, nullptr, nullptr, nullptr,
    &g_dwValueCnt, &g_dwValueMax, nullptr, nullptr, nullptr) == ERROR_SUCCESS)
    {
      if (g_dwValueCnt)
        {
          if (g_pszValue != nullptr)
            {
              free (g_pszValue);
              g_pszValue = nullptr;
            }
          g_pszValue = (LPTSTR) malloc (g_dwValueMax += 1);
          if (g_pszValue)
            {
              DWORD dwMaxValue = g_dwValueMax;
              g_dwValue = 0;
              if (RegEnumValue (hKey, g_dwValue++, g_pszValue, &dwMaxValue, 0, nullptr, nullptr, nullptr) == ERROR_SUCCESS)
                {
                  *ppszValue = g_pszValue;
                  return RegLoadVal (hKey, nullptr, g_pszValue, pValData);
                }
            }
        }
    }
  return false;
}
Exemple #22
0
// the sub-class can call this method to fill out a combo box with the values stored in
//  the recently used list.
void CAutoConfigDlg::EnumRecentlyUsed(CComboBox& cbRecentlyUsed)
{
	cbRecentlyUsed.Clear();
	CRegKey keyRecentConverterIDs;
	CString strRegKey = GetRegKey();
	if( keyRecentConverterIDs.Open(HKEY_CURRENT_USER, strRegKey) == ERROR_SUCCESS )
	{
		DWORD dwIndex = 0;
		BOOL bStop = false;
		do
		{
			DWORD dwValueType = 0, cbName = _MAX_PATH;
			TCHAR lpName[_MAX_PATH];    lpName[0] = 0;
			LONG lVal = RegEnumValue(keyRecentConverterIDs,dwIndex++,lpName,&cbName,0,&dwValueType,0,0);
			if( (lVal == ERROR_SUCCESS) || (lVal == ERROR_MORE_DATA) )
			{
				// skip the default value
				if( _tcslen(lpName) > 0 )
				{
					TRACE(_T("Found: (%s)"), lpName);
					if( cbRecentlyUsed.FindStringExact(0,lpName) < 0 )
						cbRecentlyUsed.AddString(lpName);
				}
			}
			else
				bStop = true;
		} while( !bStop );

		// select the first one so there's something in it.
		cbRecentlyUsed.SetCurSel(0);
	}
}
Exemple #23
0
static jstring getValueName(JNIEnv * env, HKEY key, jstring subkey, jint index) {
	const jchar * csubkey = env->GetStringChars(subkey, NULL);
	jstring 	result = NULL;

	HKEY skey;
	LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey);
	if (rc != ERROR_SUCCESS)
		return NULL;

	wchar_t valueName[256];
	DWORD 	nameSize = sizeof(valueName) + 2;

	rc = RegEnumValue(skey, index,
		valueName, 		// UNICODE string
		&nameSize,
		NULL, NULL,
		NULL, 			// data string
		NULL);			// size in BYTE of data.

	if (rc == ERROR_SUCCESS)
	{
		result = env->NewString((jchar *)valueName, nameSize);
	}

	RegCloseKey(skey);

	env->ReleaseStringChars(subkey, csubkey);

	return result;
}
BOOL neTKVMRegAccess::ReadValueName(LPTSTR  lpsValueName,
								 DWORD   dwNumberOfElements,
								 DWORD   dwIndex,
								 LPCTSTR lpzSubKey)
{
	BOOL bResult = FALSE;
    BYTE baData[DEFAULT_REG_ENTRY_DATA_LEN];
	DWORD dwDataSize = DEFAULT_REG_ENTRY_DATA_LEN,
		  dwType = REG_BINARY;
	HKEY hkReadKeyHandle = NULL;
   	TCHAR tcaFullRegPath[DEFAULT_REG_ENTRY_DATA_LEN];

	FormatFullRegPath(tcaFullRegPath, TBUF_SIZEOF(tcaFullRegPath), lpzSubKey);

	if (RegOpenKeyEx(m_hkPrimaryHKey,
					 tcaFullRegPath,
					 0,
					 KEY_QUERY_VALUE,
					 &hkReadKeyHandle) == ERROR_SUCCESS)
	{
		DWORD dwBuffSize = dwNumberOfElements * sizeof(lpsValueName[0]);
		if (RegEnumValue(hkReadKeyHandle,
						 dwIndex,
						 lpsValueName,
						 &dwBuffSize,
						 NULL,
						 &dwType,
						 baData,
						 &dwDataSize) == ERROR_SUCCESS)
			bResult = TRUE;
		RegCloseKey(hkReadKeyHandle);
	}

	return bResult;
}
Exemple #25
0
void DumpRegKey(DWORD dwZone, PTSTR szKey, HKEY hKey)
{
    DWORD dwIndex = 0;
    WCHAR szValueName[MAX_PATH];
    DWORD dwValueNameSize = MAX_PATH;
    BYTE  pValueData[256];
    DWORD dwType;
    DWORD dwValueDataSize = sizeof(pValueData);
    DEBUGMSG(dwZone, (TEXT("Atapi!DumpRegKey> %s \r\n"), szKey));
    while (ERROR_SUCCESS == RegEnumValue(hKey, dwIndex, szValueName, &dwValueNameSize, NULL, &dwType, pValueData, &dwValueDataSize)) {
        if (REG_SZ == dwType) {
            DEBUGMSG(dwZone, (TEXT("\t\t%s = %s\r\n"), szValueName, (LPWSTR)pValueData));
        }
        else if (REG_DWORD == dwType) {
            DEBUGMSG(dwZone, (TEXT("\t\t%s = %08X\r\n"), szValueName, *(PDWORD)pValueData));
        }
        else if (REG_MULTI_SZ == dwType) {
            PWSTR pValueTemp = (PWSTR)pValueData;
            DEBUGMSG(dwZone, (TEXT("\t\t%s :\r\n"), szValueName));
            while (*pValueTemp) {
                DEBUGMSG(dwZone, (TEXT("\t\t\t%s\r\n"), (LPWSTR)pValueTemp));
                pValueTemp += (wcslen(pValueTemp) + 1);
            }
        }
        dwIndex++;
        dwValueDataSize = sizeof(pValueData);
        dwValueNameSize = MAX_PATH;
    }
}
Exemple #26
0
void SaveSymbolSet(const TCHAR *name, TCHAR **symbols) {
  HKEY hCfgKey, hSymKey;
  if (CreateRegSettingsKey(hCfgKey)) {
    TCHAR subkey[SYMSET_SUBKEY_MAXLEN+1], bufName[8];
    CreateSymbolSetSubkeyPath(name, subkey);
    if (RegOpenKey(hCfgKey, subkey, &hSymKey) == ERROR_SUCCESS) {
      // Cannot use DeleteSymbolSet because name might be NULL and named sets are stored inside the base symbols key
      for (DWORD cb;;) {
        cb = sizeof(bufName);
        if (RegEnumValue(hSymKey,0, bufName, &cb,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS) break;
        RegDeleteValue(hSymKey, bufName);
      }
      RegCloseKey(hSymKey);
    }
    if(symbols) {
      if (RegCreateKey(hCfgKey, subkey, &hSymKey) == ERROR_SUCCESS) {
        for (SIZE_T i = 0; symbols[i]; ++i) {
          wsprintf(bufName, _T("%d"), (INT) i);
          RegWriteString(hSymKey, bufName, symbols[i]);
        }
        RegCloseKey(hSymKey);
      }
    }
    RegCloseKey(hCfgKey);
  }
}
Exemple #27
0
// Gets a registry value from the HKLM-space
int getRegParam( char *regPath, char *regItem, char *strBuffer, int strBufLen ) {
	DWORD iValue = 0;
	LONG lSuccess;
	HKEY hKey;
	char szValue[100], szData[500];
	DWORD dwType, cchValue, cbData;   

	lSuccess = RegOpenKeyEx( HKEY_LOCAL_MACHINE, regPath, 0, KEY_QUERY_VALUE, &hKey );   

	if ( lSuccess == ERROR_SUCCESS ) {
		while( TRUE )   {     
			cchValue = sizeof( szValue );     
			cbData = sizeof( szData );
			lSuccess = RegEnumValue( hKey, iValue++, szValue, &cchValue, NULL, &dwType, szData, &cbData );     
			if (lSuccess == ERROR_NO_MORE_ITEMS)       
				break;     

			if ( strcmp( szValue, regItem ) == 0 ) {
				strncpy( strBuffer, szData, strBufLen );
				return TRUE;
			}
		}
	}
	return FALSE;
}
std::vector<string> SerialPort::getAvailablePorts()
{
    std::vector<string> names;
#ifdef __WIN32__
    HKEY key;
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ | KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
    {
        char value[2048];
        unsigned long value_size = sizeof(value);
        unsigned char data[2048];
        unsigned long data_size = sizeof(data);
        int index = 0;

        while(RegEnumValue(key, index, value, &value_size, NULL, NULL, data, &data_size) == ERROR_SUCCESS)
        {
            names.push_back(string((char*)data));

            index++;
            value_size = sizeof(value);
            data_size = sizeof(value);
        }
        RegCloseKey(key);
    }else{
        LOG(ERROR) << "Failed to open registry key for serial port list.";
    }
#endif
    return names;
}
static RetainPtr<CFArrayRef> fontFilenamesFromRegistry()
{
    RetainPtr<CFMutableArrayRef> filenames(AdoptCF, CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));

    HKEY key;
    if (FAILED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), 0, KEY_READ, &key)))
        return filenames;

    DWORD valueCount;
    DWORD maxNameLength;
    DWORD maxValueLength;
    if (FAILED(RegQueryInfoKey(key, 0, 0, 0, 0, 0, 0, &valueCount, &maxNameLength, &maxValueLength, 0, 0))) {
        RegCloseKey(key);
        return filenames;
    }

    Vector<TCHAR> name(maxNameLength + 1);
    Vector<BYTE> value(maxValueLength + 1);

    for (size_t i = 0; i < valueCount; ++i) {
        DWORD nameLength = name.size();
        DWORD valueLength = value.size();
        DWORD type;
        if (FAILED(RegEnumValue(key, i, name.data(), &nameLength, 0, &type, value.data(), &valueLength)))
            continue;
        if (type != REG_SZ)
            continue;

        RetainPtr<CFDataRef> filename(AdoptCF, CFDataCreate(kCFAllocatorDefault, value.data(), valueLength));
        CFArrayAppendValue(filenames.get(), filename.get());
    }

    RegCloseKey(key);
    return filenames;
}
Exemple #30
0
	BOOL CULProfileReg::IsAutoRun(LPCTSTR pcszName)
	{
		if(pcszName==NULL)
			return FALSE;
		HKEY hKey;         
		TCHAR szKeyName[]=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
		LONG lResult=RegOpenKeyEx(((m_fAllUsers)?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER),
			szKeyName,0,KEY_QUERY_VALUE,&hKey);
		TCHAR szValNameRet[0xffff]={0};
		bool fFind=false;
		for(DWORD i=0;;++i)
		{
			DWORD dwSize=0xffff;
			//RegEnumValue сделан потому, что у меня отсутвует RegGetValue в Advapi32.dll. 
			//причины не знаю
			lResult=RegEnumValue(hKey,i,szValNameRet,&dwSize,0,0,0,0);
			if(lResult==ERROR_SUCCESS)
			{
				if(_tcscmp(pcszName,szValNameRet)==0)
				{
					fFind=true;
					break;
				}
			}
			else
				if(lResult==ERROR_NO_MORE_ITEMS)
					break;
		}
		::RegCloseKey(hKey);	
		return fFind;
	}