How to get the Windows Experience Index

21 10 2009

Description

 

 

The Windows Experience Index measures the capability of your computer’s hardware and software configuration and expresses this measurement as a number called a base score. A higher base score generally means that your computer will perform better and faster than a computer with a lower base score. How shall we calculate this base score?

BaseScore

HowCanIDoIt1

 

 

Windows Vista provides WinSAT (Windows System Assessment Tool) APIs to assesses the performance characteristics and capabilities of a computer. IProvideWinSATResultsInfo interface gives information about an assessment.

MyCodeSnippet

 

 

void CsliderctrlDlg::OnBnClickedButton2()
{
   HRESULT hr = S_OK;
   IQueryRecentWinSATAssessment* pAssessment;
   IProvideWinSATResultsInfo* pResults = NULL;
   float baseScore = 0.0;
   WINSAT_ASSESSMENT_STATE state;
   CoInitialize(NULL);
   hr = CoCreateInstance(__uuidof(CQueryWinSAT),
      NULL,
      CLSCTX_INPROC_SERVER,
      __uuidof(IQueryRecentWinSATAssessment),
      (void**)&pAssessment);
   if (SUCCEEDED(hr))
   {
      hr = pAssessment->get_Info(&pResults);
      if (SUCCEEDED(hr))
      {
         hr = pResults->get_AssessmentState(&state);
         if (SUCCEEDED(hr))
         {
            switch(state)
            {
            case WINSAT_ASSESSMENT_STATE_UNKNOWN:
               wprintf(L”The state of the assessment is unknown.\n”);
               break;
            case WINSAT_ASSESSMENT_STATE_VALID:
            case WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE:
               hr = pResults->get_SystemRating(&baseScore);
               if (SUCCEEDED(hr))
               {
                  wprintf(L”The base score for the computer is %.1f\n”, baseScore);
                  if (WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE == state)
                  {
                     wprintf(L”Note that the hardware configuration of the computer has changed\n”
                        L”since the assessment was run; the score reflects the prior configuration.”);
                  }
               }
               else
               {
                  // Handle error
               }
               break;
            case WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE:
               wprintf(L”A formal assessment has not run on the computer.\n”);
               break;
            case WINSAT_ASSESSMENT_STATE_INVALID:
               wprintf(L”The assessment data is not valid.\n”);
               break;
            default:
               wprintf(L”The assessment state value is not valid.\n”);
            }
         }
         else
         {
            // Handle error
         }
         pResults->Release();
         pResults = NULL;
      }
      else
      {
         // Handle error
      }
      pAssessment->Release();
      pAssessment = NULL;
   }
   else
   {
      // Handle error
   }
}
#include  "Winsatcominterfacei.h"
void CsliderctrlDlg::OnBnClickedButton2()
{
   HRESULT hr = S_OK;
   IQueryRecentWinSATAssessment* pAssessment;
   IProvideWinSATResultsInfo* pResults = NULL;
   float baseScore = 0.0;
   WINSAT_ASSESSMENT_STATE state;

   CoInitialize(NULL);
   hr = CoCreateInstance(__uuidof(CQueryWinSAT),
      NULL,CLSCTX_INPROC_SERVER,
      __uuidof(IQueryRecentWinSATAssessment),
      (void**)&pAssessment);

   if (SUCCEEDED(hr))
   {
      hr = pAssessment->get_Info(&pResults);
      if (SUCCEEDED(hr))
      {
         hr = pResults->get_AssessmentState(&state);
         if (SUCCEEDED(hr))
         {
            switch(state)
            {
            case WINSAT_ASSESSMENT_STATE_UNKNOWN:
               wprintf(L"The state of the assessment is unknown.\n");
               break;

            case WINSAT_ASSESSMENT_STATE_VALID:
            case WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE:
               hr = pResults->get_SystemRating(&baseScore);
               if (SUCCEEDED(hr))
               {
                  wprintf(L"The base score for the computer is %.1f\n", baseScore);
                  if (WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE == state)
                  {
                     wprintf(L"Note that the hardware configuration of the computer has changed\n"
                        L"since the assessment was run; the score reflects the prior configuration.");
                  }
               }
               else
               {  // Handle error  }
               break;
             case WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE:
               wprintf(L"A formal assessment has not run on the computer.\n");
               break;
            case WINSAT_ASSESSMENT_STATE_INVALID:
               wprintf(L"The assessment data is not valid.\n");
               break;
            default:
               wprintf(L"The assessment state value is not valid.\n");
            }
        }
         else
         {
            // Handle error
         }
         pResults->Release();
         pResults = NULL;
      }
      else
      {
         // Handle error
      }
      pAssessment->Release();
      pAssessment = NULL;
   }
   else
   {
      // Handle error
   }
}

Courtesy : MSDN

mynote9

 

 

 

Don’t forget,  its applicable only to Windows Vista and higher versions.





How To Check If Computer Is Running A 32 Bit or 64 Bit OS

12 10 2009

Description

 

 

How to check if our computer is running a 32 bit or 64 bit operating system.

HowCanIDoIt1

 

 

There are different methods to check the OS

Method 1:

Click Start, then click on Run
Type msinfo32.exe and click enter key
In System Information check the value of System Type
For 32-bit editions of Windows, the value of the System Type item is x86-based PC.
For 64-bit editions of Windows, the value of the System Type item is x64-based PC.

Method 2:

Otherwise you can use the following registry location to check it.
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor

 Just check the Identifier value.
If its x86, indicates the 32 bit and x64 indicates the 64 bit OS.

Method 3:

C++  code to check the processor.

A 32-bit application can detect whether its running under WOW64 by caling the IsWow64Process function. 

BOOL Is64BitOS()
{
   BOOL bIs64BitOS = FALSE;

   // We check if the OS is 64 Bit
   typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 

   LPFN_ISWOW64PROCESS
      fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
      GetModuleHandle("kernel32"),"IsWow64Process");
 
   if (NULL != fnIsWow64Process)
   {
      if (!fnIsWow64Process(GetCurrentProcess(),&bIs64BitOS))
      {
         //error
      }
   }
   return bIs64BitOS;
}
BOOL Is64BitOS()
{
BOOL bIs64BitOS = FALSE;
// We check if the OS is 64 Bit
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle(“kernel32″),”IsWow64Process”);
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIs64BitOS))
{
//error
}
}
return bIs64BitOS;
}




How to get the current screen resolution in pixels

1 01 2009

Some times we need to know the screen resolution of our window. Does anybody know how to get screen size?

This could be achieved by using two Windows APIs GetDesktopWindow and GetWindowRect.

GetDesktopWindow returns a handle to the desktop window. The desktop window is the window that makes up the desktop of the computer — that is, the screen.

GetWindowRect function retrieves the window’s bounding dimensions

Please check the code snippet below.

void GetScreenResolution()
{  
   RECT DesktopRect;
   // Gets the Desktop window
   HWND hDesktop=::GetDesktopWindow();
   // Gets the Desktop window rect or screen resolution in pixels
   ::GetWindowRect(hDesktop, &DesktopRect);
}




How to get the Windows OS version

31 12 2008

Microsoft divides its Operating System version numbers into two parts, Major Version Number and Minor Version Number.

Please look on the following table that summarizes the most recent operating system version numbers,

Operating system Version number
Windows Server 2008 6.0
Windows Vista 6.0
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 5.1
Windows 2000 5.0

Now wats next step, we need to get our OS version number.

Just use the windows API function GetVersion. This function retrieves the major and minor version numbers and other information about the currently running version of the operating system.

Please check the code snippet below.

void CheckOSVersion()
{ 
   DWORD dwVersion, dwMajorVersion, dwMinorVersion, dwBuild;
   dwVersion = ::GetVersion();
 
   // Gets the Major version
   dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  
   // Gets the Minor version
   dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
  
   // Get the build number. 
   if (dwVersion < 0x80000000)            
      dwBuild = (DWORD)(HIWORD(dwVersion));
   else    // Windows Me/98/95
      dwBuild =  0;
}




Getting System Information

31 12 2008

We could use the following function to get the information that describes the system configuration.

GetComputerName, GetUserName, GetSystemDirectory and GetWindowsDirectory.

Please check the code below,

void GetSystemInfos()
{
   
#define INFO_BUFFER_SIZE 32767
   
   TCHAR  infoBuf[INFO_BUFFER_SIZE];
   DWORD  bufCharCount = INFO_BUFFER_SIZE;
   
   // Get and display the name of the computer.
   GetComputerName(infoBuf, &bufCharCount );   
   
   bufCharCount = INFO_BUFFER_SIZE;
   
   // Get and display the user name.
   GetUserName( infoBuf, &bufCharCount ) ;
  
   // Get and display the system directory.
   GetSystemDirectory( infoBuf, INFO_BUFFER_SIZE );
   
   // Get and display the Windows directory.
   GetWindowsDirectory( infoBuf, INFO_BUFFER_SIZE );
   
}




How to determine whether a mouse is installed or mouse buttons are swapped

31 12 2008

The GetSystemMetrics function is used to determine whether a mouse is installed and whether the mouse buttons are swapped.

please check the code below,

void CheckMouse()
{  
   BOOL fResult;
  
   // Determine whether the mouse buttons are installed.
   fResult = GetSystemMetrics(SM_MOUSEPRESENT);
  
   if (fResult == 0)
   {
      printf("No mouse installed.\n");
   }
   else
   {
      printf("Mouse installed.\n");
     
      // Determine whether the buttons are swapped.
     
      fResult = GetSystemMetrics(SM_SWAPBUTTON);
     
      if (fResult == 0)
         printf("Buttons not swapped.\n");
      else printf("Buttons swapped.\n");
   }
}




Getting Hardware Information

30 12 2008

Do you know how to get the hardware information such as the OEM identifier, processor type, page size, and so on of your machine.

just a look at the following code snippet,

void GetHardewareInfos
{  
   SYSTEM_INFO siSysInfo;
  
   // Copy the hardware information to the SYSTEM_INFO structure.
  
   ::GetSystemInfo(&siSysInfo);
  
   // Display the contents of the SYSTEM_INFO structure.
  
   printf("Hardware information: \n");
   printf(" OEM ID: %u\n", siSysInfo.dwOemId);
   printf(" Number of processors: %u\n",
      siSysInfo.dwNumberOfProcessors);
   printf(" Page size: %u\n", siSysInfo.dwPageSize);
   printf(" Processor type: %u\n", siSysInfo.dwProcessorType);
   printf(" Minimum application address: %lx\n",
      siSysInfo.lpMinimumApplicationAddress);
   printf(" Maximum application address: %lx\n",
      siSysInfo.lpMaximumApplicationAddress);
   printf(" Active processor mask: %u\n",
      siSysInfo.dwActiveProcessorMask);  
}