GetSysInfo.h
资源名称:Visualhk.rar [点击查看]
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:10k
源码类别:
网络截获/分析
开发平台:
Visual C++
- #include "stdafx.h"
- #include "windows.h"
- #include "GetHDSerial.h"
- #define BUFSIZE 16
- /*
- 作者:海啸 lyyer English Name: Jack
- blog:http://lyyer.blog.sohu.com
- website:http://www.cnGSG.com
- 海啸网络安全组织
- */
- bool GetClientSystemInfo(SYSTEMINIT& sysinfo)
- {
- /////get computer name///////
- TCHAR computerbuf[256];
- DWORD computersize=256;
- memset(computerbuf,0,256);
- if(!GetComputerName(computerbuf,&computersize))
- return false;
- computerbuf[computersize]=0;
- sysinfo.computer[0]=0;
- //strcat(sysinfo.computer,"计算机: ");
- strcat(sysinfo.computer,computerbuf);
- ///////get user name/////////
- TCHAR userbuf[256];
- DWORD usersize=256;
- memset(userbuf,0,256);
- if(!GetUserName(userbuf,&usersize))
- return false;
- userbuf[usersize]=0;
- sysinfo.user[0]=0;
- strcat(sysinfo.user,"用户名: ");
- strcat(sysinfo.user,userbuf);
- ///////get version//////////
- OSVERSIONINFOEX osvi;
- BOOL bOsVersionInfoEx;
- /*
- char tmp[16]={0};
- //memset(sysinfo.os,0,sizeof(sysinfo.os));
- sysinfo.os[0]=0;
- // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
- // If that fails, try using the OSVERSIONINFO structure.
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
- {
- osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
- if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
- return FALSE;
- }
- switch (osvi.dwPlatformId)
- {
- // Test for the Windows NT product family.
- case VER_PLATFORM_WIN32_NT:
- // Test for the specific product family.
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
- strcpy(sysinfo.os,"Microsoft Windows Server 2003 family, ");
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
- strcpy(sysinfo.os,"Microsoft Windows XP ");
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
- strcpy(sysinfo.os,"Microsoft Windows 2000 ");
- if ( osvi.dwMajorVersion <= 4 )
- strcpy(sysinfo.os,"Microsoft Windows NT ");
- // Test for specific product on Windows NT 4.0 SP6 and later.
- if( bOsVersionInfoEx )
- {
- // Test for the workstation type.
- if ( osvi.wProductType == VER_NT_WORKSTATION )
- {
- if( osvi.dwMajorVersion == 4 )
- strcat(sysinfo.os, "Workstation 4.0 " );
- else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
- strcat(sysinfo.os, "Home Edition " );
- else
- strcat(sysinfo.os, "Professional " );
- }
- // Test for the server type.
- else if ( osvi.wProductType == VER_NT_SERVER )
- {
- if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
- {
- if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- strcat(sysinfo.os, "Datacenter Edition " );
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- strcat(sysinfo.os, "Enterprise Edition " );
- else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
- strcat(sysinfo.os, "Web Edition " );
- else
- strcat(sysinfo.os, "Standard Edition " );
- }
- else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
- {
- if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
- strcat(sysinfo.os, "Datacenter Server " );
- else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- strcat(sysinfo.os, "Advanced Server " );
- else
- strcat(sysinfo.os, "Server " );
- }
- else // Windows NT 4.0
- {
- if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
- strcat(sysinfo.os,"Server 4.0, Enterprise Edition " );
- else
- strcat(sysinfo.os, "Server 4.0 " );
- }
- }
- }
- else // Test for specific product on Windows NT 4.0 SP5 and earlier
- {
- HKEY hKey;
- char szProductType[BUFSIZE];
- DWORD dwBufLen=BUFSIZE;
- LONG lRet;
- lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "SYSTEM\CurrentControlSet\Control\ProductOptions",
- 0, KEY_QUERY_VALUE, &hKey );
- if( lRet != ERROR_SUCCESS )
- return FALSE;
- lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
- (LPBYTE) szProductType, &dwBufLen);
- if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
- return FALSE;
- RegCloseKey( hKey );
- if ( lstrcmpi( "WINNT", szProductType) == 0 )
- strcat(sysinfo.os, "Workstation " );
- if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
- strcat(sysinfo.os, "Server " );
- if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
- strcat(sysinfo.os,"Advanced Server " );
- printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
- }
- // Display service pack (if any) and build number.
- if( osvi.dwMajorVersion == 4 &&
- lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
- {
- HKEY hKey;
- LONG lRet;
- // Test for SP6 versus SP6a.
- lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Hotfix\Q246009",
- 0, KEY_QUERY_VALUE, &hKey );
- if( lRet == ERROR_SUCCESS )
- {
- sprintf( tmp,"Service Pack 6a (Build %d)n", osvi.dwBuildNumber & 0xFFFF );
- strcat(sysinfo.os, tmp );
- }
- else // Windows NT 4.0 prior to SP6a
- {
- sprintf( tmp,"%s (Build %d)n",
- osvi.szCSDVersion,
- osvi.dwBuildNumber & 0xFFFF);
- strcat(sysinfo.os, tmp );
- }
- RegCloseKey( hKey );
- }
- else // Windows NT 3.51 and earlier or Windows 2000 and later
- {
- sprintf(tmp, "%s (Build %d)n",
- osvi.szCSDVersion,
- osvi.dwBuildNumber & 0xFFFF);
- strcat(sysinfo.os, tmp );
- }
- break;
- // Test for the Windows 95 product family.
- case VER_PLATFORM_WIN32_WINDOWS:
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
- {
- strcpy(sysinfo.os,"Microsoft Windows 95 ");
- if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
- strcat(sysinfo.os,"OSR2 " );
- }
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
- {
- strcpy(sysinfo.os,"Microsoft Windows 98 ");
- if ( osvi.szCSDVersion[1] == 'A' )
- strcat(sysinfo.os,"SE " );
- }
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
- {
- strcpy(sysinfo.os,"Microsoft Windows Millennium Editionn");
- }
- break;
- case VER_PLATFORM_WIN32s:
- printf ("Microsoft Win32sn");
- break;
- }
- */
- OSVERSIONINFOEX osviex;
- sysinfo.os[0]=0;
- memset(&osviex,0,sizeof(OSVERSIONINFOEX));
- osviex.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if(GetVersionEx((LPOSVERSIONINFO)&osviex)==0)
- {
- //OutputDebugString("GetVersionEx Error: %dn",GetLastError());
- OutputDebugString("GetVersionEx Error");
- return FALSE;
- }
- switch(osviex.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_NT:
- switch(osviex.dwMajorVersion)
- {
- case 4:
- if(osviex.dwMinorVersion == 0)
- strcat(sysinfo.os,"Microsoft Windows NT 4");
- break;
- case 5:
- if(osviex.dwMinorVersion == 0)
- {
- strcat(sysinfo.os,"Microsoft Windows 2000 ");
- }
- else if(osviex.dwMinorVersion == 1)
- {
- strcat(sysinfo.os,"Windows XP ");
- }
- else if(osviex.dwMinorVersion == 2)
- {
- strcat(sysinfo.os,"Windows 2003 ");
- }
- }
- break;
- }
- //*/
- /*
- ///////////get disk space/////////////
- sysinfo.disk[0]=0;
- //strcat(sysinfo.disk,"磁盘空间: ");
- DWORD maskdriver;
- ULONGLONG totalspace=0,freespace=0;
- ULONGLONG ulltotalspace,ullfreespace,freebyte;
- DWORD drivertype;
- char driver[10];
- if(!(maskdriver=GetLogicalDrives()))
- return false;
- for(int i=0;i<26;i++)
- {
- if(!(maskdriver>>i))
- break;
- if(maskdriver>>i&1)
- {
- driver[0]=i+'A';
- driver[1]=':';
- driver[2]='\';
- driver[3]=0;
- drivertype=GetDriveType(driver);
- if(drivertype!=DRIVE_FIXED)
- continue;
- if(!GetDiskFreeSpaceEx (driver,
- (PULARGE_INTEGER)&freebyte,
- (PULARGE_INTEGER)&ulltotalspace,
- (PULARGE_INTEGER)&ullfreespace))
- return false;
- totalspace+=ulltotalspace;
- freespace+=ullfreespace;
- }
- }
- signed __int64 dfreespace=0.0,dtotalspace=0.0,lv;
- dfreespace=(signed __int64)freespace/(1024*1024*1024);
- dtotalspace=(signed __int64)totalspace/(1024*1024*1024);
- lv=(signed __int64)freespace/totalspace*100;
- char space[256];
- sprintf(space,"总磁盘空间为:%.2fG,剩余磁盘空间为:%.2fG(占%.2f%c)",dtotalspace,dfreespace,lv,'%');
- strcat(sysinfo.disk,space);
- */
- //////////////////get HardDisk serial /////////////////////////////////////////
- char *temp;
- sysinfo.HDSerial[0]=0;
- CGetHDSerial HDSerial; // 创建实例
- temp=HDSerial.GetHDSerial(); // 得到硬盘序列号
- strcat(sysinfo.HDSerial,temp);
- ////////////////get cpu info//////////////////
- sysinfo.processor[0]=0;
- //strcat(sysinfo.processor,"CPU: ");
- HKEY hKey;
- char szcpuinfo[80];
- DWORD dwBufLen=80;
- RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "HARDWARE\DESCRIPTION\System\CentralProcessor\0",
- 0, KEY_QUERY_VALUE, &hKey );
- RegQueryValueEx( hKey, "VendorIdentifier", NULL, NULL,
- (LPBYTE)szcpuinfo, &dwBufLen);
- szcpuinfo[dwBufLen]=0;
- //strcat(sysinfo.processor,szcpuinfo);
- //strcat(sysinfo.processor," ");
- memset(szcpuinfo,0,80);
- dwBufLen=80;
- RegQueryValueEx( hKey, "Identifier", NULL, NULL,
- (LPBYTE)szcpuinfo, &dwBufLen);
- szcpuinfo[dwBufLen]=0;
- //strcat(sysinfo.processor,szcpuinfo);
- DWORD f;
- dwBufLen=8;
- RegQueryValueEx( hKey, "~MHz", NULL, NULL,
- (LPBYTE)&f, &dwBufLen);
- char hz[10];
- sprintf(hz," %dMHZ",f);
- strcat(sysinfo.processor,hz);
- RegCloseKey(hKey);
- /////////////get mem size////////////
- MEMORYSTATUS ms;
- GlobalMemoryStatus(&ms);
- char membuf[256];//物理内存:
- // sprintf(membuf,"总物理内存:%dMB,可用内存:%dMB (占%.2f%s)",ms.dwTotalPhys/1024/1024,ms.dwAvailPhys/1024/1024
- // ,(double)ms.dwAvailPhys/ms.dwTotalPhys*100,"%");
- sprintf(membuf,"%dMB",ms.dwTotalPhys/1024/1024);
- sysinfo.mem[0]=0;
- strcpy(sysinfo.mem,membuf);
- return true;
- }