HRESULT CVBoxMachine::Exec(const wchar_t* pszCommandLine, DWORD* ppid, HANDLE* phProcess)
{
	// Get from the InstallDir registry key
	CUniString strVBoxPath;
	RegGetString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Oracle\\VirtualBox", L"InstallDir", strVBoxPath);

	// If that fails, assume program files...
	if (strVBoxPath.IsEmpty())
	{
		// Work out path to vbox
		GetSpecialFolderLocation(CSIDL_PROGRAM_FILES, L"Oracle\\VirtualBox", false, strVBoxPath);
	}

	// Remove trailing backslash
	RemoveTrailingBackslash(strVBoxPath.GetBuffer());

	CUniString str=StringReplace(pszCommandLine, L"{vboxdir}", strVBoxPath, true);
	str=StringReplace(str, L"{machinename}", m_strMachineName, true);

	// Setup startup info
	STARTUPINFO si;
	memset(&si, 0, sizeof(si));
	si.cb=sizeof(si);

	// Setup process info
	PROCESS_INFORMATION pi;
	memset(&pi, 0, sizeof(pi));

	// Create the process
	if (!CreateProcess(NULL, str.GetBuffer(), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
	{
		return HRESULT_FROM_WIN32(GetLastError());
	}


	// Close/return handles
	if (phProcess)
	{
		phProcess[0]=pi.hProcess;
	}
	else
	{
		CloseHandle(pi.hProcess);
	}
	CloseHandle(pi.hThread);

	// Return the process ID
	if (ppid)
	{
		ppid[0]=pi.dwProcessId;
	}

	return S_OK;
}
Exemplo n.º 2
0
CUniString SIMPLEAPI SlxGetProfileString(const wchar_t* pszSection, const wchar_t* pszEntry, const wchar_t* pszDefault)
{
	ASSERT(!IsEmptyString(g_strAppName));

	if (g_bFileBased)
	{
		return g_ProfileFile.GetValue(pszSection, pszEntry, pszDefault);
	}
	else
	{
		CUniString str;
		if (RegGetString(HKEY_CURRENT_USER, SlxGetProfileKey(pszSection), pszEntry, str)!=ERROR_SUCCESS)
			return pszDefault;
		return str;
	}

}
Exemplo n.º 3
0
static void _SlxConvertProfileRegKey(const wchar_t* pszRegKey, CProfileSection* pSection)
{
	// Open sub key
	CSmartHandle<HKEY> Key;
	if (RegOpenKeyEx(HKEY_CURRENT_USER, pszRegKey, 0, KEY_READ, &Key)==ERROR_SUCCESS)
	{

		// Enumerate all values
		DWORD dwIndex=0;
		TCHAR szName[MAX_PATH];
		DWORD cbName=MAX_PATH;
		DWORD dwType;
		while (RegEnumValue(Key, dwIndex++, szName, &cbName, NULL, &dwType, NULL, NULL)==ERROR_SUCCESS)
		{
			switch (dwType)
			{
				case REG_SZ:
				{
					CUniString str;
					if (RegGetString(Key, NULL, szName, str)==ERROR_SUCCESS)
					{
						pSection->SetValue(szName, str);
					}
					break;
				}

				case REG_DWORD:
				{
					DWORD dw;
					if (RegGetDWORD(Key, NULL, szName, &dw)==ERROR_SUCCESS)
					{
						pSection->SetIntValue(szName, dw);
					}
					break;
				}

				case REG_BINARY:
				{
					CAutoPtr<IStream, SRefCounted> spStreamSrc;
					if (SUCCEEDED(OpenRegistryStream(Key, NULL, szName, &spStreamSrc)))
					{
						CAutoPtr<IStream, SRefCounted> spStreamDest;
						if (SUCCEEDED(CreateProfileStream(pSection->CreateEntry(szName), NULL, &spStreamDest)))
						{
							CopyStream(spStreamDest, spStreamSrc);
						}
					}
					break;
				}
			}


			// Reset size
			cbName=MAX_PATH;
		}

		Key.Release();
	}

	// Copy sub sections
	CUniStringVector vecSubSections;
	RegEnumAllKeys(HKEY_CURRENT_USER, pszRegKey, vecSubSections);
	for (int i=0; i<vecSubSections.GetSize(); i++)
	{
		_SlxConvertProfileRegKey(Format(L"%s\\%s", pszRegKey, vecSubSections[i]), pSection->CreateSection(vecSubSections[i]));
	}

}