29 #include <boost/algorithm/string.hpp>
35 wchar_t **wchar_argv = CommandLineToArgvW(GetCommandLineW(), &nargs);
41 for(
int i=0;i<nargs;++i)
42 args.push_back(stdext::utf16_to_utf8(wchar_argv[i]));
48 std::string commandLine;
49 for(
uint i = 0; i < args.size(); ++i)
56 std::wstring wfile = stdext::utf8_to_utf16(process);
57 std::wstring wcommandLine = stdext::utf8_to_utf16(commandLine);
59 if((
size_t)ShellExecuteW(NULL, L
"open", wfile.c_str(), wcommandLine.c_str(), NULL, SW_SHOWNORMAL) > 32)
66 return GetCurrentProcessId();
71 if(FindWindowA(name.c_str(), NULL) != NULL)
78 HWND
window = FindWindowA(name.c_str(), NULL);
81 DWORD pid = GetProcessId(
window);
82 HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS,
false, pid);
85 bool ok = TerminateProcess(handle, 1) != 0;
93 wchar_t path[MAX_PATH];
94 GetTempPathW(MAX_PATH, path);
95 ret = stdext::utf16_to_utf8(path);
103 wchar_t path[MAX_PATH];
104 GetCurrentDirectoryW(MAX_PATH, path);
105 ret = stdext::utf16_to_utf8(path);
114 std::wstring wfile = stdext::utf8_to_utf16(file);
115 DWORD dwAttrib = GetFileAttributesW(wfile.c_str());
116 return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
123 if(CopyFileW(stdext::utf8_to_utf16(from).c_str(), stdext::utf8_to_utf16(to).c_str(), FALSE) == 0)
131 if(DeleteFileW(stdext::utf8_to_utf16(file).c_str()) == 0)
139 std::wstring wfile = stdext::utf8_to_utf16(file);
140 WIN32_FILE_ATTRIBUTE_DATA fileAttrData;
141 memset(&fileAttrData, 0,
sizeof(fileAttrData));
142 GetFileAttributesExW(wfile.c_str(), GetFileExInfoStandard, &fileAttrData);
144 uli.LowPart = fileAttrData.ftLastWriteTime.dwLowDateTime;
145 uli.HighPart = fileAttrData.ftLastWriteTime.dwHighDateTime;
151 if(url.find(
"http://") == std::string::npos)
152 url.insert(0,
"http://");
153 ShellExecuteW(NULL, L
"open", stdext::utf8_to_utf16(url).c_str(), NULL, NULL, SW_SHOWNORMAL);
159 memset(buf, 0,
sizeof(buf));
160 DWORD bufSize =
sizeof(buf);
162 if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
164 RegQueryValueExA(hKey,
"ProcessorNameString", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufSize);
170 MEMORYSTATUSEX status;
171 status.dwLength =
sizeof(status);
172 GlobalMemoryStatusEx(&status);
173 return status.ullTotalPhys;
176 #ifndef PRODUCT_PROFESSIONAL
177 #define PRODUCT_PROFESSIONAL 0x00000030
178 #define VER_SUITE_WH_SERVER 0x00008000
179 #define VER_PLATFORM_WIN32s 0
180 #define VER_PLATFORM_WIN32_WINDOWS 1
181 #define VER_PLATFORM_WIN32_NT 2
182 #define PRODUCT_UNDEFINED 0x00000000
183 #define PRODUCT_ULTIMATE 0x00000001
184 #define PRODUCT_HOME_BASIC 0x00000002
185 #define PRODUCT_HOME_PREMIUM 0x00000003
186 #define PRODUCT_ENTERPRISE 0x00000004
187 #define PRODUCT_HOME_BASIC_N 0x00000005
188 #define PRODUCT_BUSINESS 0x00000006
189 #define PRODUCT_STANDARD_SERVER 0x00000007
190 #define PRODUCT_DATACENTER_SERVER 0x00000008
191 #define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
192 #define PRODUCT_ENTERPRISE_SERVER 0x0000000A
193 #define PRODUCT_STARTER 0x0000000B
194 #define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
195 #define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
196 #define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
197 #define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
198 #define PRODUCT_BUSINESS_N 0x00000010
199 #define PRODUCT_WEB_SERVER 0x00000011
200 #define PRODUCT_CLUSTER_SERVER 0x00000012
201 #define PRODUCT_HOME_SERVER 0x00000013
202 #define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
203 #define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
204 #define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
205 #define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
206 #define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
207 #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
208 #define PRODUCT_HOME_PREMIUM_N 0x0000001A
209 #define PRODUCT_ENTERPRISE_N 0x0000001B
210 #define PRODUCT_ULTIMATE_N 0x0000001C
211 #define PRODUCT_WEB_SERVER_CORE 0x0000001D
212 #define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E
213 #define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F
214 #define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020
215 #define PRODUCT_SERVER_FOUNDATION 0x00000021
216 #define PRODUCT_HOME_PREMIUM_SERVER 0x00000022
217 #define PRODUCT_SERVER_FOR_SMALLBUSINESS_V 0x00000023
218 #define PRODUCT_STANDARD_SERVER_V 0x00000024
219 #define PRODUCT_DATACENTER_SERVER_V 0x00000025
220 #define PRODUCT_ENTERPRISE_SERVER_V 0x00000026
221 #define PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027
222 #define PRODUCT_STANDARD_SERVER_CORE_V 0x00000028
223 #define PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029
224 #define PRODUCT_HYPERV 0x0000002A
225 #define PRODUCT_STORAGE_EXPRESS_SERVER_CORE 0x0000002B
226 #define PRODUCT_STORAGE_STANDARD_SERVER_CORE 0x0000002C
227 #define PRODUCT_STORAGE_WORKGROUP_SERVER_CORE 0x0000002D
228 #define PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE 0x0000002E
229 #define PRODUCT_STARTER_N 0x0000002F
230 #define PRODUCT_PROFESSIONAL 0x00000030
231 #define PRODUCT_PROFESSIONAL_N 0x00000031
232 #define PRODUCT_SB_SOLUTION_SERVER 0x00000032
237 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
238 typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
241 OSVERSIONINFOEX osvi;
245 BOOL bOsVersionInfoEx;
248 ZeroMemory(&si,
sizeof(SYSTEM_INFO));
249 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
251 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
252 bOsVersionInfoEx = VerifyVersionInfo(&osvi, 0, 0);
254 if(!bOsVersionInfoEx)
255 return std::string();
257 pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT(
"kernel32.dll")),
"GetNativeSystemInfo");
263 if(VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4) {
264 if(osvi.dwMajorVersion == 6) {
265 if(osvi.dwMinorVersion == 0) {
266 if(osvi.wProductType == VER_NT_WORKSTATION)
267 ret +=
"Windows Vista ";
268 else ret +=
"Windows Server 2008 ";
271 if(osvi.dwMinorVersion == 1 || osvi.dwMinorVersion == 2)
273 if(osvi.wProductType == VER_NT_WORKSTATION && osvi.dwMinorVersion == 1)
276 if(osvi.wProductType == VER_NT_WORKSTATION && osvi.dwMinorVersion == 2)
279 ret +=
"Windows Server 2008 R2 ";
282 pGPI = (PGPI) GetProcAddress(GetModuleHandle(TEXT(
"kernel32.dll")),
"GetProductInfo");
284 pGPI( osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
288 case PRODUCT_ULTIMATE:
289 ret +=
"Ultimate Edition";
291 case PRODUCT_PROFESSIONAL:
292 ret +=
"Professional";
294 case PRODUCT_HOME_PREMIUM:
295 ret +=
"Home Premium Edition";
297 case PRODUCT_HOME_BASIC:
298 ret +=
"Home Basic Edition";
300 case PRODUCT_ENTERPRISE:
301 ret +=
"Enterprise Edition";
303 case PRODUCT_BUSINESS:
304 ret +=
"Business Edition";
306 case PRODUCT_STARTER:
307 ret +=
"Starter Edition";
309 case PRODUCT_CLUSTER_SERVER:
310 ret +=
"Cluster Server Edition";
312 case PRODUCT_DATACENTER_SERVER:
313 ret +=
"Datacenter Edition";
315 case PRODUCT_DATACENTER_SERVER_CORE:
316 ret +=
"Datacenter Edition (core installation)";
318 case PRODUCT_ENTERPRISE_SERVER:
319 ret +=
"Enterprise Edition";
321 case PRODUCT_ENTERPRISE_SERVER_CORE:
322 ret +=
"Enterprise Edition (core installation)";
324 case PRODUCT_ENTERPRISE_SERVER_IA64:
325 ret +=
"Enterprise Edition for Itanium-based Systems";
327 case PRODUCT_SMALLBUSINESS_SERVER:
328 ret +=
"Small Business Server";
330 case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
331 ret +=
"Small Business Server Premium Edition";
333 case PRODUCT_STANDARD_SERVER:
334 ret +=
"Standard Edition";
336 case PRODUCT_STANDARD_SERVER_CORE:
337 ret +=
"Standard Edition (core installation)";
339 case PRODUCT_WEB_SERVER:
340 ret +=
"Web Server Edition";
345 if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) {
346 if(GetSystemMetrics(SM_SERVERR2))
347 ret +=
"Windows Server 2003 R2, ";
348 else if(osvi.wSuiteMask & VER_SUITE_STORAGE_SERVER)
349 ret +=
"Windows Storage Server 2003";
350 else if(osvi.wSuiteMask & VER_SUITE_WH_SERVER)
351 ret +=
"Windows Home Server";
352 else if(osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
353 ret +=
"Windows XP Professional x64 Edition";
355 ret +=
"Windows Server 2003, ";
357 if(osvi.wProductType != VER_NT_WORKSTATION) {
358 if(si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64) {
359 if(osvi.wSuiteMask & VER_SUITE_DATACENTER)
360 ret +=
"Datacenter Edition for Itanium-based Systems";
361 else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
362 ret +=
"Enterprise Edition for Itanium-based Systems";
365 else if(si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
366 if(osvi.wSuiteMask & VER_SUITE_DATACENTER)
367 ret +=
"Datacenter x64 Edition";
368 else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
369 ret +=
"Enterprise x64 Edition";
371 ret +=
"Standard x64 Edition";
373 if(osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
374 ret +=
"Compute Cluster Edition";
375 else if(osvi.wSuiteMask & VER_SUITE_DATACENTER)
376 ret +=
"Datacenter Edition";
377 else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
378 ret +=
"Enterprise Edition";
379 else if(osvi.wSuiteMask & VER_SUITE_BLADE)
380 ret +=
"Web Edition";
381 else ret +=
"Standard Edition";
386 if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) {
387 ret +=
"Windows XP ";
388 if(osvi.wSuiteMask & VER_SUITE_PERSONAL)
389 ret +=
"Home Edition";
390 else ret +=
"Professional";
393 if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
394 ret +=
"Windows 2000 ";
395 if(osvi.wProductType == VER_NT_WORKSTATION) {
396 ret +=
"Professional";
398 if(osvi.wSuiteMask & VER_SUITE_DATACENTER)
399 ret +=
"Datacenter Server";
400 else if(osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
401 ret +=
"Advanced Server";
402 else ret +=
"Server";
408 if(osvi.dwMajorVersion >= 6 ) {
409 if(si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
411 else if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL )
423 std::stringstream ss;
425 ss <<
"\n\t[C++]: " << where;