VC获取IE路径

#include "RegUtil.h"

BOOL IsWow64() 
{ 
	typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); 
	LPFN_ISWOW64PROCESS fnIsWow64Process; 
	BOOL bIsWow64 = FALSE; 
	fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process"); 
	if (NULL != fnIsWow64Process) 
	{ 
		fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
	} 
	return bIsWow64; 
} 

BOOL GetIEPath(_TCHAR IEPath[MAX_PATH])
{
	TCHAR SysPath[MAX_PATH] = {0};
	GetSystemDirectory(SysPath, MAX_PATH);
	memset(IEPath, 0, MAX_PATH * sizeof(_TCHAR));
	IEPath[0] = SysPath[0];
	if (IsWow64())
	{
		lstrcat(IEPath, _T(":\\Program Files (x86)\\Internet Explorer\\iexplore.exe"));
	}
	else
	{
		lstrcat(IEPath, _T(":\\Program Files\\Internet Explorer\\iexplore.exe"));
	}


	if (!PathFileExists(IEPath))
	{
		GetRegValue(IEPath, HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE"), NULL, REG_NONE);
		// 严防出现腾讯TT事件
		if (!_tcsstr(IEPath, _T("iexplore.exe")))
		{
			memset(IEPath, 0, MAX_PATH * sizeof(_TCHAR));
		}
	}

	return PathFileExists(IEPath);	
}


附: RegUtil


#pragma once

#include <tchar.h>
#include <windows.h>

#ifdef __REG__API
#define	REG_API	
#else
#define REG_API extern
#endif

namespace RegUtil
{
	REG_API LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwValue);
	REG_API LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR lpszValue);
	REG_API LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, const BYTE* lpData, DWORD cbData, DWORD dwType = REG_SZ);

	REG_API LSTATUS GetRegValue(TCHAR* RegValue, HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPDWORD cbData, DWORD dwType);
	REG_API LSTATUS GetRegValue(TCHAR* RegValue, HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType = REG_SZ);

}


#include "stdafx.h"

#ifndef	__REG__API
#define	__REG__API
#endif

#include "RegUtil.h"

#include <Aclapi.h>
#include <shobjidl.h>

namespace RegUtil
{
	LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, const BYTE* lpData, DWORD cbData, DWORD dwType)
	{
		LSTATUS RetVal;
		HKEY hKey;
		const REGSAM samDesired = PCInfo::IsWow64() ? KEY_SET_VALUE | KEY_WOW64_64KEY : KEY_SET_VALUE;
		if (ERROR_SUCCESS != RegOpenKeyEx(MainKey, lpSubKey, 0, samDesired, &hKey))
		{
			HKEY phkResult;
			RetVal = RegCreateKey(MainKey, lpSubKey, &phkResult);
			if (RetVal == ERROR_SUCCESS)
			{
				RetVal = RegOpenKeyEx(MainKey, lpSubKey, 0, samDesired, &hKey);
				if (RetVal != ERROR_SUCCESS)
					return RetVal;
			}
			else
			{
				return RetVal;
			}
		}
		RetVal = RegSetValueEx(hKey, lpValueName, NULL, dwType, lpData, cbData);
		RegCloseKey(hKey);
		return RetVal;
	}

	LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwValue)
	{
		return SetRegValue(MainKey, lpSubKey, lpValueName, (BYTE *)&dwValue, sizeof(DWORD), REG_DWORD);
	}

	LSTATUS SetRegValue(HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR lpszValue)
	{
#ifdef UNICODE
		DWORD cbData = 2 * lstrlenW(lpszValue);
#else
		DWORD cbData = lstrlenA(lpszValue);
#endif
		return SetRegValue(MainKey, lpSubKey, lpValueName, (BYTE *)lpszValue, cbData);
	}

	LSTATUS GetRegValue(TCHAR* RegValue, HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPDWORD cbData, DWORD dwType)
	{
		LSTATUS RetVal = ERROR_SUCCESS;
		HKEY hKey;
		const REGSAM samDesired = PCInfo::IsWow64() ? KEY_READ | KEY_WOW64_64KEY : KEY_READ;
		RetVal = RegOpenKeyEx(MainKey, lpSubKey, 0, samDesired, &hKey);
		if (RetVal == ERROR_SUCCESS)
		{
			RetVal = RegQueryValueEx(hKey, lpValueName, NULL, &dwType , (LPBYTE)RegValue, cbData);
			RegCloseKey(hKey);
		}
		return RetVal;
	}

	LSTATUS GetRegValue(TCHAR* RegValue, HKEY MainKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType)
	{
		DWORD cbData = 512;
		return GetRegValue(RegValue, MainKey, lpSubKey, lpValueName, &cbData, dwType);
	}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值