593 lines
15 KiB
C++
593 lines
15 KiB
C++
// AyaSysInfo.cpp: implementation of the CAyaSysInfo class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "AyaSysInfo.h"
|
|
#include "crc32static.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
#define MAXNETLOOP 20
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CAyaSysInfo::CAyaSysInfo()
|
|
{
|
|
|
|
}
|
|
|
|
CAyaSysInfo::~CAyaSysInfo()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
//return basic system information
|
|
CString CAyaSysInfo::GetSysInfo()
|
|
{
|
|
CString strTemp,strReturn;
|
|
DWORD dwWhatever=255;
|
|
char chBuff[255];
|
|
char ch;
|
|
int x=0;
|
|
long lDriveType;
|
|
memset(chBuff,0,sizeof(int));
|
|
|
|
strReturn.Empty();
|
|
strReturn="SYSTEM INFORMATION:\r\n";
|
|
//computer name
|
|
if(GetComputerName(chBuff,&dwWhatever))
|
|
strTemp.Format("Computer name: [%s]\r\n",chBuff);
|
|
strReturn+=strTemp;
|
|
|
|
strReturn += GetOpSysVersion() + "\r\n";
|
|
|
|
|
|
|
|
//local drive letters
|
|
if(GetLogicalDriveStrings(255,chBuff))
|
|
{
|
|
strReturn+="Drive information:\r\n";
|
|
strTemp.Empty();
|
|
ch=chBuff[x];
|
|
do{
|
|
|
|
strTemp+=ch;
|
|
strTemp+=":\\";
|
|
lDriveType=GetDriveType(strTemp);
|
|
|
|
switch (lDriveType)
|
|
{
|
|
case DRIVE_NO_ROOT_DIR:
|
|
strTemp+=" - No root path determinable. Invalid\r\n";
|
|
break;
|
|
case DRIVE_REMOVABLE:
|
|
strTemp+=" - Removable drive\r\n";
|
|
break;
|
|
case DRIVE_FIXED:
|
|
strTemp+=" - Fixed drive\r\n";
|
|
break;
|
|
case DRIVE_REMOTE:
|
|
strTemp+=" - remote network drive\r\n";
|
|
break;
|
|
case DRIVE_CDROM:
|
|
strTemp+=" - CDROM drive\r\n";
|
|
break;
|
|
case DRIVE_RAMDISK:
|
|
strTemp+=" - RAM drive\r\n";
|
|
break;
|
|
default:
|
|
strTemp+=" - Unknown type\r\n";
|
|
|
|
|
|
}
|
|
strReturn+= "\t" + strTemp;
|
|
strTemp.Empty();
|
|
x+=4;
|
|
ch=chBuff[x];
|
|
}while(ch!=0);
|
|
|
|
|
|
}
|
|
|
|
//memory
|
|
strReturn+="\r\n";
|
|
MEMORYSTATUS ms;
|
|
GlobalMemoryStatus(&ms);
|
|
|
|
strTemp.Format("RAM: %ld kb of physical memory\r\n",ms.dwTotalPhys/1024);
|
|
strReturn+=strTemp;
|
|
|
|
strTemp.Format("RAM: %ld percent of memory is in use\r\n",ms.dwMemoryLoad);
|
|
strReturn+=strTemp;
|
|
|
|
return strReturn;
|
|
}
|
|
|
|
|
|
//Get locale information
|
|
CString CAyaSysInfo::GetLocalInfo()
|
|
{
|
|
CString strTemp,strReturn;
|
|
char chBuff[50];
|
|
memset(chBuff,0,sizeof(int));
|
|
|
|
strReturn.Empty();
|
|
strReturn="LOCALE INFORMATION:\r\n";
|
|
|
|
//short date format
|
|
if(GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE,chBuff,50))
|
|
strTemp.Format("Short date format: [%s]\r\n",chBuff);
|
|
strReturn+=strTemp;
|
|
|
|
//Currency symbol
|
|
if(GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SCURRENCY,chBuff,50))
|
|
strTemp.Format("Currency symbol: [%s]\r\n",chBuff);
|
|
strReturn+=strTemp;
|
|
|
|
//language
|
|
if(GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SENGLANGUAGE ,chBuff,50))
|
|
strTemp.Format("Language: [%s]\r\n",chBuff);
|
|
strReturn+=strTemp;
|
|
|
|
//Country
|
|
if(GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SCOUNTRY,chBuff,50))
|
|
strTemp.Format("Country: [%s]\r\n",chBuff);
|
|
strReturn+=strTemp;
|
|
|
|
return strReturn;
|
|
}
|
|
|
|
|
|
//Get info from every function and return it all
|
|
CString CAyaSysInfo::GetAllInfo()
|
|
{
|
|
CString strReturn;
|
|
strReturn.Empty();
|
|
|
|
//Local info
|
|
strReturn=GetLocalInfo();
|
|
strReturn+="\r\n" + GetSysInfo();
|
|
|
|
return strReturn;
|
|
}
|
|
|
|
|
|
|
|
//os version info
|
|
CString CAyaSysInfo::GetOpSysVersion()
|
|
{
|
|
CString strReturn, strTemp;
|
|
strReturn="Operating system: [";
|
|
OSVERSIONINFOEX osvi;
|
|
BOOL bOsVersionInfoEx;
|
|
|
|
// Try calling GetVersionEx using the OSVERSIONINFOEX structure,
|
|
// which is supported on Windows 2000.
|
|
//
|
|
// If that fails, try using the OSVERSIONINFO structure.
|
|
|
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
|
|
{
|
|
// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
|
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
|
|
return "OS VERSION UNKNOWN";
|
|
}
|
|
|
|
switch (osvi.dwPlatformId)
|
|
{
|
|
case VER_PLATFORM_WIN32_NT:
|
|
|
|
if(osvi.dwMajorVersion < 4)
|
|
strReturn+="Windows NT pre v4.0 ";
|
|
|
|
if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion== 0)
|
|
strReturn+="Windows NT 4.0 ";
|
|
|
|
if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion== 0)
|
|
strReturn+="Windows 2000 ";
|
|
|
|
if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion== 1)
|
|
strReturn+="Windows XP ";
|
|
|
|
if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion== 2)
|
|
strReturn+="Windows server 2003 family ";
|
|
|
|
// 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 )
|
|
strReturn+= "Workstation 4.0 " ;
|
|
else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
|
|
strReturn+="Home Edition ";
|
|
else
|
|
strReturn+="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 )
|
|
strReturn+="Datacenter Edition " ;
|
|
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
|
|
strReturn+="Enterprise Edition ";
|
|
else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
|
|
strReturn+="Web Edition ";
|
|
else
|
|
strReturn+="Standard Edition ";
|
|
}
|
|
|
|
else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
|
|
{
|
|
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
|
|
strReturn+="Datacenter Server ";
|
|
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
|
|
strReturn+="Advanced Server ";
|
|
else
|
|
strReturn+="Server ";
|
|
}
|
|
|
|
else // Windows NT 4.0
|
|
{
|
|
if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
|
|
strReturn+="Server 4.0, Enterprise Edition ";
|
|
else
|
|
strReturn+="Server 4.0 ";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
strTemp.Format("%s",osvi.szCSDVersion);
|
|
strTemp.TrimLeft(" ");
|
|
if(strTemp.IsEmpty())
|
|
strTemp="n/a";
|
|
strReturn+= " Version: " + strTemp;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion== 0)
|
|
strReturn+="Windows 95";
|
|
|
|
if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion== 10)
|
|
strReturn+="Windows 98";
|
|
|
|
if(osvi.dwMajorVersion == 4 && osvi.dwMinorVersion== 90)
|
|
strReturn+="Windows ME";
|
|
|
|
strTemp.Format("%s",osvi.szCSDVersion);
|
|
strTemp.TrimLeft(" ");
|
|
if(strTemp.IsEmpty())
|
|
strTemp="n/a";
|
|
strReturn+= " Version: " + strTemp;
|
|
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32s:
|
|
|
|
strReturn+="Microsoft Win32s \r\n";
|
|
break;
|
|
}
|
|
strReturn+="]\r\n";
|
|
return strReturn;
|
|
}
|
|
|
|
//usage: pass in a path or file name
|
|
//returns all files if just a path
|
|
//or details on the one file if a single file
|
|
//with crc32 checksums
|
|
//does *not* recurse
|
|
CString CAyaSysInfo::GetFilesInfo(CString strStartPath)
|
|
{
|
|
CString strReturn, strTemp, strSize;
|
|
CFileFind ff;
|
|
CTime ct,wt;
|
|
CCrc32Static crc;
|
|
DWORD dwcheck=0;
|
|
|
|
|
|
|
|
unsigned int uiFileSize;
|
|
bool bGotPath=false;
|
|
BOOL bWorking = ff.FindFile(strStartPath);
|
|
|
|
//Change 02/20/2003
|
|
if(!bWorking)
|
|
strReturn.Format("File not found",strStartPath);
|
|
|
|
while (bWorking)
|
|
{
|
|
bWorking = ff.FindNextFile();
|
|
|
|
// skip . and .. files; otherwise, we'd
|
|
// recurse infinitely!
|
|
|
|
if (ff.IsDots())
|
|
continue;
|
|
if(ff.IsDirectory())
|
|
{ if(bGotPath==false)
|
|
{
|
|
strTemp.Format("<Files in: %s>\r\n",ff.GetRoot());
|
|
strReturn+=strTemp;
|
|
bGotPath=true;
|
|
}
|
|
ff.GetCreationTime(ct);
|
|
strTemp.Format("\r\n\\%-45s\t%s\t<folder>\r\n",ff.GetFileName(),ct.Format("%b.%d.%Y %H:%M:%S"));
|
|
strReturn+=strTemp;
|
|
|
|
}
|
|
else //it's a file, get file info
|
|
{
|
|
if(bGotPath==false)
|
|
{
|
|
strTemp.Format("<Files in: %s>\r\n",ff.GetRoot());
|
|
strReturn+=strTemp;
|
|
bGotPath=true;
|
|
}
|
|
ff.GetCreationTime(ct);
|
|
ff.GetLastWriteTime(wt);
|
|
uiFileSize=(UINT)ff.GetLength();
|
|
if(uiFileSize < 1024)
|
|
strSize.Format("%u bytes",uiFileSize);
|
|
else
|
|
{
|
|
//convert to KB
|
|
uiFileSize=uiFileSize/1024;
|
|
strSize.Format("%u KB",uiFileSize);
|
|
|
|
}
|
|
|
|
crc.FileCrc32Assembly(ff.GetFilePath(),dwcheck);
|
|
|
|
strTemp.Format("%-35s\tC:%-15s\tW:%-15s\t%-8s\tcrc: %08x\r\n",ff.GetFileName(),
|
|
ct.Format("%b.%d.%Y %H:%M:%S"),wt.Format("%b.%d.%Y %H:%M:%S"),strSize,dwcheck);
|
|
strReturn+=strTemp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
ff.Close();
|
|
return strReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
CString CAyaSysInfo::GetNetworkResources(LPNETRESOURCE lpnr)
|
|
{
|
|
m_lLoop++;
|
|
m_lDepth++;
|
|
if(m_lLoop>MAXNETLOOP)
|
|
return "Overflow";
|
|
CString strTemp, strReturn, strLastResource, strThisResource;
|
|
|
|
|
|
DWORD dwResult, dwResultEnum;
|
|
HANDLE hEnum;
|
|
DWORD cbBuffer = 16384; // 16K is a good size
|
|
DWORD cEntries = -1; // enumerate all possible entries
|
|
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
|
|
DWORD i;
|
|
|
|
|
|
//
|
|
// Call the WNetOpenEnum function to begin the enumeration.
|
|
//
|
|
dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources
|
|
RESOURCETYPE_ANY, // all resources
|
|
0, // enumerate all resources
|
|
lpnr, // NULL first time the function is called
|
|
&hEnum); // handle to the resource
|
|
|
|
if (dwResult != NO_ERROR)
|
|
{
|
|
//
|
|
// Process errors with an application-defined error handler.
|
|
//
|
|
//NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
|
|
return "Network resources - FAIL";
|
|
}
|
|
//
|
|
// Call the GlobalAlloc function to allocate resources.
|
|
//
|
|
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
|
|
|
|
do
|
|
{
|
|
//strReturn+="Calling Enumerate from master...\r\n";
|
|
//
|
|
// Initialize the buffer.
|
|
//
|
|
ZeroMemory(lpnrLocal, cbBuffer);
|
|
//
|
|
// Call the WNetEnumResource function to continue
|
|
// the enumeration.
|
|
//
|
|
dwResultEnum = WNetEnumResource(hEnum, // resource handle
|
|
&cEntries, // defined locally as -1
|
|
lpnrLocal, // LPNETRESOURCE
|
|
&cbBuffer); // buffer size
|
|
//
|
|
// If the call succeeds, loop through the structures.
|
|
//
|
|
strTemp.Format("\r\n\tdwResult=%i, loop=%u, CEntries=%i",dwResultEnum,m_lLoop, cEntries);
|
|
strReturn+=strTemp;
|
|
if (dwResultEnum == NO_ERROR)
|
|
{
|
|
strReturn+="\r\n\tNoError\r\n";
|
|
//strTemp.Format("CEntries=%i\r\n",cEntries);
|
|
//strReturn+=strTemp;
|
|
for(i = 0; i < cEntries; i++)
|
|
{
|
|
|
|
|
|
if(RESOURCEUSAGE_CONTAINER != (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
|
|
{
|
|
if(i==0)
|
|
{
|
|
strTemp.Format("%s",lpnrLocal[i].lpProvider);
|
|
if(!strTemp.IsEmpty() && strTemp!="(null)")
|
|
strReturn+= "Provider: " + strTemp + "";
|
|
}
|
|
|
|
strTemp.Format("%s",lpnrLocal[i].lpLocalName);
|
|
if(!strTemp.IsEmpty() && strTemp!="(null)")
|
|
strReturn+= "Local name: " + strTemp + " ";
|
|
|
|
strTemp.Format("%s",lpnrLocal[i].lpRemoteName);
|
|
if(!strTemp.IsEmpty() && strTemp!="(null)")
|
|
{
|
|
strReturn+= "\r\n\tRemote name: " + strTemp + " ";
|
|
strThisResource=strTemp;
|
|
}
|
|
strTemp.Format("%s",lpnrLocal[i].lpComment);
|
|
if(!strTemp.IsEmpty() && strTemp!="(null)")
|
|
strReturn+= " (Comment: " + strTemp + ")\r\n";
|
|
|
|
}
|
|
// If the NETRESOURCE structure represents a container resource,
|
|
// call the EnumerateFunc function recursively.
|
|
|
|
if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
|
|
if(lpnrLocal[i].lpProvider!="HP Network Printers")
|
|
strReturn+=GetNetworkResources(&lpnrLocal[i]);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
// Process errors.
|
|
//
|
|
|
|
}
|
|
//
|
|
// End do.
|
|
//
|
|
while(dwResultEnum != ERROR_NO_MORE_ITEMS);
|
|
//
|
|
// Call the GlobalFree function to free the memory.
|
|
//
|
|
GlobalFree((HGLOBAL)lpnrLocal);
|
|
//
|
|
// Call WNetCloseEnum to end the enumeration.
|
|
//
|
|
dwResult = WNetCloseEnum(hEnum);
|
|
|
|
if(dwResult != NO_ERROR)
|
|
{
|
|
//
|
|
// Process errors.
|
|
//
|
|
//NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
|
|
return "Network resources - FAIL";
|
|
}
|
|
|
|
//returning
|
|
// m_lLoop--;
|
|
m_lDepth--;
|
|
strTemp.Format("\r\nDepth=%u\r\n",m_lDepth);
|
|
strReturn+=strTemp;
|
|
return strReturn;
|
|
|
|
|
|
}
|
|
*/
|
|
/*
|
|
//usage: pass in a path or file name
|
|
//returns all files if just a path
|
|
//or details on the one file if a single file
|
|
//does *not* recurse
|
|
CString CAyaSysInfo::GetFilesInfo(CString strStartPath)
|
|
{
|
|
CString strReturn, strTemp, strSize;
|
|
CFileFind ff;
|
|
CTime ct,wt;
|
|
unsigned int uiFileSize;
|
|
bool bGotPath=false;
|
|
BOOL bWorking = ff.FindFile(strStartPath);
|
|
|
|
while (bWorking)
|
|
{
|
|
bWorking = ff.FindNextFile();
|
|
|
|
// skip . and .. files; otherwise, we'd
|
|
// recur infinitely!
|
|
|
|
if (ff.IsDots())
|
|
continue;
|
|
if(ff.IsDirectory())
|
|
{ if(bGotPath==false)
|
|
{
|
|
strTemp.Format("<Files in: %s>\r\n",ff.GetRoot());
|
|
strReturn+=strTemp;
|
|
bGotPath=true;
|
|
}
|
|
ff.GetCreationTime(ct);
|
|
strTemp.Format("%-45s\t%s\t<folder>\r\n",ff.GetFileName(),ct.Format("%b.%d.%Y %H:%M:%S"));
|
|
strReturn+=strTemp;
|
|
|
|
}
|
|
else //it's a file, get file info
|
|
{
|
|
if(bGotPath==false)
|
|
{
|
|
strTemp.Format("<Files in: %s>\r\n",ff.GetRoot());
|
|
strReturn+=strTemp;
|
|
bGotPath=true;
|
|
}
|
|
ff.GetCreationTime(ct);
|
|
ff.GetLastWriteTime(wt);
|
|
uiFileSize=ff.GetLength();
|
|
if(uiFileSize < 1024)
|
|
strSize.Format("%u bytes",uiFileSize);
|
|
else
|
|
{
|
|
//convert to KB
|
|
uiFileSize=uiFileSize/1024;
|
|
strSize.Format("%u KB",uiFileSize);
|
|
|
|
}
|
|
|
|
|
|
strTemp.Format("%-45s\tC:%s\tW:%s\t%s\r\n",ff.GetFileName(),
|
|
ct.Format("%b.%d.%Y %H:%M:%S"),wt.Format("%b.%d.%Y %H:%M:%S"),strSize);
|
|
strReturn+=strTemp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
ff.Close();
|
|
return strReturn;
|
|
|
|
}
|
|
*/ |