00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CArchSystemWindows.h"
00020 #include "CArchMiscWindows.h"
00021 #include "XArchWindows.h"
00022
00023 #include "tchar.h"
00024 #include <string>
00025
00026 static const char* s_settingsKeyNames[] = {
00027 _T("SOFTWARE"),
00028 _T("Synergy"),
00029 NULL
00030 };
00031
00032
00033
00034
00035
00036 CArchSystemWindows::CArchSystemWindows()
00037 {
00038
00039 }
00040
00041 CArchSystemWindows::~CArchSystemWindows()
00042 {
00043
00044 }
00045
00046 std::string
00047 CArchSystemWindows::getOSName() const
00048 {
00049 #if WINVER >= _WIN32_WINNT_WIN2K
00050 OSVERSIONINFOEX info;
00051 #else
00052 OSVERSIONINFO info;
00053 #endif
00054
00055 info.dwOSVersionInfoSize = sizeof(info);
00056 if (GetVersionEx((OSVERSIONINFO*) &info)) {
00057 switch (info.dwPlatformId) {
00058 case VER_PLATFORM_WIN32_NT:
00059 #if WINVER >= _WIN32_WINNT_WIN2K
00060 if (info.dwMajorVersion == 6) {
00061 if(info.dwMinorVersion == 0) {
00062 if (info.wProductType == VER_NT_WORKSTATION) {
00063 return "Microsoft Windows Vista";
00064 } else {
00065 return "Microsoft Windows Server 2008";
00066 }
00067 } else if(info.dwMinorVersion == 1) {
00068 if (info.wProductType == VER_NT_WORKSTATION) {
00069 return "Microsoft Windows 7";
00070 } else {
00071 return "Microsoft Windows Server 2008 R2";
00072 }
00073 }
00074 }
00075 #endif
00076
00077 if (info.dwMajorVersion == 5 && info.dwMinorVersion == 2) {
00078 return "Microsoft Windows Server 2003";
00079 }
00080 if (info.dwMajorVersion == 5 && info.dwMinorVersion == 1) {
00081 return "Microsoft Windows XP";
00082 }
00083 if (info.dwMajorVersion == 5 && info.dwMinorVersion == 0) {
00084 return "Microsoft Windows Server 2000";
00085 }
00086 if (info.dwMajorVersion <= 4) {
00087 return "Microsoft Windows NT";
00088 }
00089 char buffer[100];
00090 sprintf(buffer, "Microsoft Windows %d.%d",
00091 info.dwMajorVersion, info.dwMinorVersion);
00092 return buffer;
00093
00094 case VER_PLATFORM_WIN32_WINDOWS:
00095 if (info.dwMajorVersion == 4 && info.dwMinorVersion == 0) {
00096 if (info.szCSDVersion[1] == 'C' ||
00097 info.szCSDVersion[1] == 'B') {
00098 return "Microsoft Windows 95 OSR2";
00099 }
00100 return "Microsoft Windows 95";
00101 }
00102 if (info.dwMajorVersion == 4 && info.dwMinorVersion == 10) {
00103 if (info.szCSDVersion[1] == 'A') {
00104 return "Microsoft Windows 98 SE";
00105 }
00106 return "Microsoft Windows 98";
00107 }
00108 if (info.dwMajorVersion == 4 && info.dwMinorVersion == 90) {
00109 return "Microsoft Windows ME";
00110 }
00111 if (info.dwMajorVersion == 4) {
00112 return "Microsoft Windows unknown 95 family";
00113 }
00114 break;
00115
00116 default:
00117 break;
00118 }
00119 }
00120 return "Microsoft Windows <unknown>";
00121 }
00122
00123 std::string
00124 CArchSystemWindows::getPlatformName() const
00125 {
00126 #ifdef _X86_
00127 if(isWOW64())
00128 return "x86 (WOW64)";
00129 else
00130 return "x86";
00131 #else
00132 #ifdef _AMD64_
00133 return "x64";
00134 #else
00135 return "Unknown";
00136 #endif
00137 #endif
00138 }
00139
00140 std::string
00141 CArchSystemWindows::setting(const std::string& valueName) const
00142 {
00143 HKEY key = CArchMiscWindows::openKey(HKEY_LOCAL_MACHINE, s_settingsKeyNames);
00144 if (key == NULL)
00145 return "";
00146
00147 return CArchMiscWindows::readValueString(key, valueName.c_str());
00148 }
00149
00150 void
00151 CArchSystemWindows::setting(const std::string& valueName, const std::string& valueString) const
00152 {
00153 HKEY key = CArchMiscWindows::addKey(HKEY_LOCAL_MACHINE, s_settingsKeyNames);
00154 if (key == NULL)
00155 throw XArch(std::string("could not access registry key: ") + valueName);
00156 CArchMiscWindows::setValue(key, valueName.c_str(), valueString.c_str());
00157 }
00158
00159 bool
00160 CArchSystemWindows::isWOW64() const
00161 {
00162 #if WINVER >= _WIN32_WINNT_WINXP
00163 typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
00164 HMODULE hModule = GetModuleHandle(TEXT("kernel32"));
00165 if (!hModule) return FALSE;
00166
00167 LPFN_ISWOW64PROCESS fnIsWow64Process =
00168 (LPFN_ISWOW64PROCESS) GetProcAddress(hModule, "IsWow64Process");
00169
00170 BOOL bIsWow64 = FALSE;
00171 if(NULL != fnIsWow64Process &&
00172 fnIsWow64Process(GetCurrentProcess(), &bIsWow64) &&
00173 bIsWow64)
00174 {
00175 return true;
00176 }
00177 #endif
00178 return false;
00179 }