//********************************************************************************
BOOL CRegValue::ReadValue(LPBYTE* pValue, const REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nType != GetValueType())
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   *pValue = new BYTE[nSize];

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &m_nType, *pValue, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      {
      delete *pValue;
      return FALSE;
      }
   return TRUE;
   }
Exemple #2
0
//-------------------------------------------------------------------------------
CRegKeyInfo::CRegKeyInfo(const CRegKey& regkey)
{
    m_pClassName = NULL;
    if(! regkey.IsOpen())
    {
        SetResultCode(errKeyNotOpen);
        return;
    }
    DWORD nSize = 0;

    SetOSResult(::RegQueryInfoKey(regkey.GetKey(), NULL, &nSize,
                                  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));

    if(GetOSResult() != ERROR_SUCCESS)
    {
        SetResultCode(errRegistry);
        return;
    }

    nSize += 1;
    m_pClassName = new TCHAR[nSize];
    SetOSResult(::RegQueryInfoKey(regkey.GetKey(), m_pClassName, &nSize, NULL,
                                  &m_nNumOfSubKeys, &m_nMaxSubKeyName, &m_nMaxClassName, &m_nNumOfValues,
                                  &m_nMaxValueName, &m_nMaxValueLen, &m_nSecurityDescLen, &m_ftLastWrite));

    if(GetOSResult() != ERROR_SUCCESS)
    {
        delete m_pClassName;
        m_pClassName = NULL;
        SetResultCode(errRegistry);
    }
}
//********************************************************************************
BOOL CRegValue::ReadValue(LPDWORD pValue, REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nSize != sizeof(DWORD))
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, (UCHAR*) pValue, &nSize));

   return GetOSResult() == ERROR_SUCCESS;
   }
//********************************************************************************
BOOL CRegValue::WriteValue(const LPBYTE pValue, DWORD nSize)
   {
   if(GetValueType() == -1)
      {
      SetResultCode(errUninitializedValueType);
      return FALSE;
      }

   SetOSResult(::RegSetValueEx(GetKey(), GetValueName(), 0, GetValueType(), (UCHAR*) pValue, nSize));

   return GetOSResult() == ERROR_SUCCESS;
   }
//********************************************************************************
BOOL CRegValue::ReadValue(CString& sValue, const REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nType != GetValueType())
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &m_nType,
      (UCHAR*) sValue.GetBuffer(nSize), &nSize));

   sValue.ReleaseBuffer();

   return GetOSResult() == ERROR_SUCCESS;
   }
//********************************************************************************
BOOL CRegValue::IterateEnumValue()
   {
   if(m_nEnum < 0)
      return FALSE;

   TCHAR sTemp[1024];
   DWORD nSize = sizeof(sTemp);

   SetOSResult(::RegEnumValue(GetKey(), m_nEnum, sTemp, &nSize,
      NULL, &m_nType, NULL, NULL));

   SetValueName(sTemp);

   m_nEnum += m_nEnumDirection;

   return GetOSResult() == ERROR_SUCCESS;
   }
//********************************************************************************
BOOL CRegValue::DeleteValue()
   {
   SetOSResult(::RegDeleteValue(GetKey(), GetValueName()));

   return GetOSResult() == ERROR_SUCCESS;
   }
//--------------------------------------------------------------------------------
CExecuteApp::CExecuteApp(LPCTSTR pExe, LPCTSTR pParams, LPCTSTR pPath, DWORD nWaitTime)
		: m_hProcess(NULL)
		, m_nExitCode(0xffffffff)
	{
	SHELLEXECUTEINFO info;
	::ZeroMemory(&info, sizeof(SHELLEXECUTEINFO));
	info.cbSize = sizeof(SHELLEXECUTEINFO);
	info.fMask = SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS;
	info.lpFile = pExe;
	info.lpParameters = pParams;
	info.lpDirectory = pPath;
	info.nShow = SW_HIDE;

	SetResultCode(errOS);

	if(! ::ShellExecuteEx(&info))
		{
		SetOSResult(GetLastError());
		DebugPrintf(_T("ShellExecuteEx(%s,'%s','%s') error=%ld\n"), info.lpFile, pParams, pPath, GetOSResult());
		return;
		}

	m_hProcess = info.hProcess;

	if(nWaitTime != 0)
		{
		if(::WaitForSingleObject(m_hProcess, nWaitTime) != WAIT_OBJECT_0)
			{
			DebugPrintf(_T("wait on info.hProcess failed\n"));
			return;
			}

		BOOL bRunOk = ::GetExitCodeProcess(m_hProcess, &m_nExitCode);

		if(!bRunOk || m_nExitCode != 0)
			{
			DebugPrintf(_T("%s exits with %ld\n"), info.lpFile, m_nExitCode);
			return;
			}
		}
	}