获取系统版本信息和列举进程PID号

iMac posted @ 2009年4月25日 15:28 , 870 阅读

 

// Testing.cpp : 定义控制台应用程序的入口点。
//
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <Windows.h>
#include <Tlhelp32.h>
using namespace std;
void main()
{
        OSVERSIONINFO osverinfo;
        osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        GetVersionEx(&osverinfo);
 
        cout<<"MajorVersion:"<<osverinfo.dwMajorVersion<<endl;
        cout<<"MinorVersion:"<<osverinfo.dwMinorVersion<<endl;  
        cout<<" BuildNumber:"<<osverinfo.dwBuildNumber<<endl;
        cout<<"  PlatformID:"<<osverinfo.dwPlatformId<<endl;
        cout<<"   CSVersion:"<<osverinfo.szCSDVersion<<endl;
        cout<<"-------------------------------------------"<<endl;
        DWORD dwProcessID=0;
        PROCESSENTRY32 pe;
        pe.dwSize = sizeof(PROCESSENTRY32);
        HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL | TH32CS_SNAPMODULE, 0);
        //获取第一个进程的信息
        Process32First(hSnapshot, &pe);
        cout<<endl; 
 
        do 
        {
                cout<<pe.th32ProcessID<<endl;
                pe.dwSize = sizeof(PROCESSENTRY32);
        }
        while (Process32Next(hSnapshot, &pe));
 
        CloseHandle(hSnapshot);
        //关闭快照句柄
}
 

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter