得到任务管理器的正在执行的程序列表 系统的临时路径及临时文件绝对路径

#include "windows.h"
#include "tlhelp32.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
    PROCESSENTRY32 pe32;
    //在使用这个结构前,先设置它的大小
    pe32.dwSize = sizeof(pe32);
    //给系统内所有的进程拍个快照
    HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    if (hProcessSnap == INVALID_HANDLE_VALUE)
    {
        printf("CreateToolhelp32Snapshot 调用失败.\n");
        return -1;
    }
    //遍历进程快照,轮流显示每个进程的信息
    BOOL bMore = ::Process32First(hProcessSnap,&pe32);
    while (bMore)
    {
        printf("进程名称:%s\n",pe32.szExeFile);
        printf("进程ID:%u\n\n",pe32.th32ProcessID);
        bMore = ::Process32Next(hProcessSnap,&pe32);
    }
    //不要忘记清除掉snapshot对象
    ::CloseHandle(hProcessSnap);
    return 0;
} 

1. 得到任务管理器的正在执行的程序列表

2. 系统的临时路径及临时文件绝对路径

#include <windows.h>
#include <stdio.h>
void main()
{
    DWORD dwRetVal = 0;
    UINT uRetVal   = 0;
    TCHAR lpTempPathBuffer[MAX_PATH];
    TCHAR szTempFileName[MAX_PATH];

    dwRetVal = GetTempPath(MAX_PATH,          // length of the buffer
                           lpTempPathBuffer); // buffer for path 
    if (dwRetVal > MAX_PATH || (dwRetVal == 0))
    {
        return (2);
    }

    //  Generates a temporary file name. 
    uRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp files
                              TEXT("DEMO"),     // temp file name prefix 
                              0,                // create unique name 
                              szTempFileName);  // buffer for name 
    if (uRetVal == 0)
    {
        return (3);
    }

    printf("%s\n%s\n",lpTempPathBuffer,szTempFileName);
    return 0;
}

vs2008

posted @ 2012-09-06 17:18  upendi  Views(374)  Comments(0Edit  收藏  举报