mirror of http://192.168.10.5:8099/sane/release
122 lines
3.4 KiB
C++
122 lines
3.4 KiB
C++
|
#include <Windows.h>
|
|||
|
#include <atlstr.h>
|
|||
|
#include <tlhelp32.h>
|
|||
|
|
|||
|
static CStringA GetInstallLocation(const CStringA& guid)
|
|||
|
{
|
|||
|
CStringA strInstallLoc;
|
|||
|
|
|||
|
HKEY hKey = NULL;
|
|||
|
CStringA strSubKey;
|
|||
|
strSubKey.Format("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s", (LPCSTR)guid);
|
|||
|
RegOpenKeyExA(HKEY_LOCAL_MACHINE, strSubKey, 0, KEY_QUERY_VALUE, &hKey);
|
|||
|
if (NULL != hKey)
|
|||
|
{
|
|||
|
CHAR szData[MAX_PATH] = { 0 };
|
|||
|
DWORD cbData = MAX_PATH;
|
|||
|
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "InstallLocation", NULL, NULL, (LPBYTE)szData, &cbData))
|
|||
|
{
|
|||
|
strInstallLoc = szData;
|
|||
|
}
|
|||
|
|
|||
|
RegCloseKey(hKey);
|
|||
|
}
|
|||
|
|
|||
|
return strInstallLoc;
|
|||
|
}
|
|||
|
|
|||
|
static bool AppIsRun(const CStringA& guid, const CStringA& appName)
|
|||
|
{
|
|||
|
CStringA strInstallLoc = GetInstallLocation(guid);
|
|||
|
if (strInstallLoc.IsEmpty())
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
CStringW strAppPath2(strInstallLoc);
|
|||
|
CStringW strAppName2(appName);
|
|||
|
|
|||
|
bool ret = false;
|
|||
|
HANDLE hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|||
|
if (hSnapshot != INVALID_HANDLE_VALUE)
|
|||
|
{
|
|||
|
PROCESSENTRY32 pe;
|
|||
|
pe.dwSize = sizeof(PROCESSENTRY32);
|
|||
|
BOOL bFindFirstProcess = ::Process32First(hSnapshot, &pe);
|
|||
|
if (bFindFirstProcess)
|
|||
|
{
|
|||
|
do
|
|||
|
{
|
|||
|
WCHAR exeFullPath[1024] = { 0 };
|
|||
|
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
|
|||
|
if (NULL != hProcess)
|
|||
|
{
|
|||
|
DWORD bufferLen = 1024;
|
|||
|
::QueryFullProcessImageName(hProcess, 0, exeFullPath, &bufferLen);
|
|||
|
::CloseHandle(hProcess);
|
|||
|
}
|
|||
|
|
|||
|
CStringW strExeFullPath(exeFullPath);
|
|||
|
int pos = strExeFullPath.ReverseFind('\\');
|
|||
|
if (-1 != pos)
|
|||
|
{
|
|||
|
CStringW strExeName = strExeFullPath.Right(strExeFullPath.GetLength() - pos - 1);
|
|||
|
|
|||
|
strExeFullPath.MakeLower();
|
|||
|
strAppPath2.MakeLower();
|
|||
|
if (0 == _wcsicmp(strExeName, strAppName2) && NULL != wcsstr(strExeFullPath, strAppPath2))
|
|||
|
{
|
|||
|
ret = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
} while (::Process32Next(hSnapshot, &pe));
|
|||
|
}
|
|||
|
|
|||
|
::CloseHandle(hSnapshot);
|
|||
|
}
|
|||
|
|
|||
|
return ret;
|
|||
|
}
|
|||
|
|
|||
|
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
|||
|
_In_opt_ HINSTANCE hPrevInstance,
|
|||
|
_In_ LPWSTR lpCmdLine,
|
|||
|
_In_ int nCmdShow)
|
|||
|
{
|
|||
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|||
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|||
|
|
|||
|
CStringA strAppGuid, strAppName;
|
|||
|
#if defined(OEM_HANWANG)
|
|||
|
#ifdef _WIN64
|
|||
|
strAppGuid = "{91B3FC8D-CA10-4754-9339-6794D4D922F6}_is1";
|
|||
|
#else
|
|||
|
strAppGuid = "{4486975C-CBCF-430B-BED1-427866D1738E}_is1";
|
|||
|
#endif
|
|||
|
strAppName = "HanvonScan.exe";
|
|||
|
#elif defined(OEM_LISICHENG)
|
|||
|
#ifdef _WIN64
|
|||
|
strAppGuid = "{05FD7C3E-C683-4FB4-9DD4-E4DE94985BEF}_is1";
|
|||
|
#else
|
|||
|
strAppGuid = "{F2890F43-A51C-4379-BB79-992616B1D6BD}_is1";
|
|||
|
#endif
|
|||
|
strAppName = "LanxumScan.exe";
|
|||
|
#else
|
|||
|
#ifdef _WIN64
|
|||
|
strAppGuid = "{F50A4E10-3E42-446C-A63A-DF7848C61B31}_is1";
|
|||
|
#else
|
|||
|
strAppGuid = "{7076DC53-5C2F-4216-9783-2A6F954FEB3E}_is1";
|
|||
|
#endif
|
|||
|
strAppName = "HuaGoScan.exe";
|
|||
|
#endif
|
|||
|
|
|||
|
if (AppIsRun(strAppGuid, strAppName))
|
|||
|
{
|
|||
|
return 2;
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|