Retrieve server/host Windows version

Not one of the easiest jobs, is retrieving the version information of your Windows computer with PHP. Other methods are available, but they don’t show you the exact version, usually just report WINNT or similair strings. The code below will print the full information on your computer, easy as that…

    $com_object = new COM ( 'winmgmts://localhost/root/CIMV2' );
    $os =  $com_object->ExecQuery("Select * from Win32_OperatingSystem");

    foreach ($os as $os_data )
    {
                //  Windows version information e.g. 6.1.7600  for Windows 7
		$windows_version = $os_data->Version; 
                // Full name of Windows version e.g. Microsoft Windows 7 Professional 
		$windows_caption = $os_data->Caption; 
                // Major Service Pack version (0 if not available)
		$windows_sp = $os_data->ServicePackMajorVersion; 
    }
   

This entry was posted in Wordpress. Bookmark the permalink.