#include "PcInfo.h"
bool isConnect() {
DWORD dwCb = sizeof(RASCONN);
DWORD dwErr = ERROR_SUCCESS;
DWORD dwRetries = 5;
DWORD dwConnections = 0;
RASCONN* lpRasConn = NULL;
RASCONNSTATUS* lpRasStatus = NULL;
while (dwRetries--)
{
//
// If the memory is allocated, free it.
//
if (NULL != lpRasConn)
{
HeapFree(GetProcessHeap(), 0, lpRasConn);
lpRasConn = NULL;
}
lpRasConn = (RASCONN*) HeapAlloc(GetProcessHeap(), 0, dwCb);
if (NULL == lpRasConn)
{
dwErr = ERROR_NOT_ENOUGH_MEMORY;
break;
}
// Set the structure size for version checking purposes.
//
lpRasConn->dwSize = sizeof(RASCONN);
//
// Call the RAS API then exit the loop if we are successful or an unknown
// error occurs.
//
dwErr = RasEnumConnections(
lpRasConn,
&dwCb,
&dwConnections);
if (ERROR_BUFFER_TOO_SMALL != dwErr)
{
break;
}
}
if (ERROR_SUCCESS == dwErr)
{
for (register unsigned int i = 0; i < dwConnections; i++)
{
RasGetConnectStatus(lpRasConn[i].hrasconn, lpRasStatus);
if(lpRasStatus->rasconnstate = RASCS_Connected) {
HeapFree(GetProcessHeap(), 0, lpRasConn);
lpRasConn = NULL;
return true;
}
}
}
if (NULL != lpRasConn)
{
HeapFree(GetProcessHeap(), 0, lpRasConn);
lpRasConn = NULL;
}
return false;
}
char* getPercentRamInUse() {
double bytesBusy = atof(getBytesBusyRam());
double maxBytes = atof(getBytesMaxRam());
double percent = (100 * bytesBusy) / maxBytes;
return fcvt(percent, 2, NULL, NULL);
}
char* getBytesMaxRam() {
MEMORYSTATUS memory;
GlobalMemoryStatus(&memory);
return ultoa(memory.dwTotalPhys/1024, NULL, 10);
}
char* getBytesFreeRam() {
MEMORYSTATUS memory;
GlobalMemoryStatus(&memory);
return ultoa(memory.dwAvailPhys/1024, NULL, 10);
}
char* getBytesBusyRam() {
MEMORYSTATUS memory;
GlobalMemoryStatus(&memory);
return (getBytesMaxRam() - (memory.dwAvailPhys/1024));
}
char* getSystemDirectory() {
char* systemDir = new char[MAX_PATH];
GetSystemDirectory(systemDir, 50);
return systemDir;
}
char* getWindowsDirectory() {
char* winDir = new char[MAX_PATH];
GetWindowsDirectory(winDir, 50);
return winDir;
}
bool isNT() {
return !(0x80000000 & GetVersion());
}
char* getSerialVolume(char* volume) {
unsigned long seriale;
GetVolumeInformation(volume, NULL, 0, &seriale, 0, 0, NULL, 0);
return ltoa(seriale, NULL, 10);
}
//thanks to softzone
char* getvelox() {
unsigned __int64 x;
unsigned __int64 *dest = &x;
__asm
{
_emit 0xf
_emit 0x31
mov esi, dest
mov [esi], eax
mov [esi+4], edx
}
return _ui64toa(x, NULL, 10);
}
char* getSpace(char* volume, int use) {
unsigned __int64 lpFreeBytesAvaibleToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
unsigned __int64 space = NULL;
GetDiskFreeSpaceEx(volume, (PULARGE_INTEGER)&lpFreeBytesAvaibleToCaller,
(PULARGE_INTEGER) &lpTotalNumberOfBytes,
(PULARGE_INTEGER) &lpTotalNumberOfFreeBytes);
switch(use) {
case FREE:
space = lpTotalNumberOfFreeBytes;
break;
case USED:
space = lpTotalNumberOfBytes - lpTotalNumberOfFreeBytes;
break;
case TOTAL:
space = lpTotalNumberOfBytes;
break;
}
return _ui64toa(space, NULL, 10);
}