CreateToolHelp32Snapshot查模块拒绝服务为什么?

解决方案 »

  1.   

    CreateToolhelp32Snapshot
    Takes a snapshot of the processes and the heaps, modules, and threads used by the processes.HANDLE WINAPI CreateToolhelp32Snapshot(
      DWORD dwFlags,       
      DWORD th32ProcessID  
    );
    Parameters
    dwFlags 
    [in] Specifies portions of the system to include in the snapshot. This parameter can be one of the following values. Value Meaning 
    TH32CS_INHERIT Indicates that the snapshot handle is to be inheritable. 
    TH32CS_SNAPALL Equivalent to specifying TH32CS_SNAPHEAPLIST, TH32CS_SNAPMODULE, TH32CS_SNAPPROCESS, and TH32CS_SNAPTHREAD. 
    TH32CS_SNAPHEAPLIST Includes the heap list of the specified process in the snapshot. 
    TH32CS_SNAPMODULE Includes the module list of the specified process in the snapshot. 
    TH32CS_SNAPPROCESS Includes the process list in the snapshot. 
    TH32CS_SNAPTHREAD Includes the thread list in the snapshot. 
    th32ProcessID 
    [in] Specifies the process identifier. This parameter can be zero to indicate the current process. This parameter is used when the TH32CS_SNAPHEAPLIST or TH32CS_SNAPMODULE value is specified. Otherwise, it is ignored. 
    Return Values
    Returns an open handle to the specified snapshot if successful or INVALID_HANDLE_VALUE otherwise. Res
    The snapshot taken by this function is examined by the other tool help functions to provide their results. Access to the snapshot is read only. The snapshot handle acts like an object handle and is subject to the same rules regarding which processes and threads it is valid in. To retrieve an extended error status code generated by this function, use the GetLastError function.To destroy the snapshot, use the CloseHandle function.
      

  2.   

    Taking a Snapshot and Viewing Processes
    The following example obtains a list of running processes. First, the GetProcessList function takes a snapshot of the currently executing processes in the system using the CreateToolhelp32Snapshot function, then it walks through the list recorded in the snapshot, using the Process32First and Process32Next functions. For each process, the function calls GetProcessModule, which is defined in Traversing the module list. #include <windows.h>
    #include <tlhelp32.h>
    #include <stdio.h>BOOL GetProcessList () 

        HANDLE         hProcessSnap = NULL; 
        BOOL           bRet      = FALSE; 
        PROCESSENTRY32 pe32      = {0}; 
     
        //  Take a snapshot of all processes in the system.     hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);     if (hProcessSnap == INVALID_HANDLE_VALUE) 
            return (FALSE); 
     
        //  Fill in the size of the structure before using it.     pe32.dwSize = sizeof(PROCESSENTRY32); 
     
        //  Walk the snapshot of the processes, and for each process, 
        //  display information.     if (Process32First(hProcessSnap, &pe32)) 
        { 
            DWORD         dwPriorityClass; 
            BOOL          bGotModule = FALSE; 
            MODULEENTRY32 me32       = {0}; 
     
            do 
            { 
                bGotModule = GetProcessModule(pe32.th32ProcessID, 
                    pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32));             if (bGotModule) 
                { 
                    HANDLE hProcess; 
     
                    // Get the actual priority class. 
                    hProcess = OpenProcess (PROCESS_ALL_ACCESS, 
                        FALSE, pe32.th32ProcessID); 
                    dwPriorityClass = GetPriorityClass (hProcess); 
                    CloseHandle (hProcess);                 // Print the process's information. 
                    printf( "\nPriority Class Base\t%d\n", 
                        pe32.pcPriClassBase); 
                    printf( "PID\t\t\t%d\n", pe32.th32ProcessID);
                    printf( "Thread Count\t\t%d\n", pe32.cntThreads);
                    printf( "Module Name\t\t%s\n", me32.szModule);
                    printf( "Full Path\t\t%s\n\n", me32.szExePath);
                } 
            } 
            while (Process32Next(hProcessSnap, &pe32)); 
            bRet = TRUE; 
        } 
        else 
            bRet = FALSE;    // could not walk the list of processes 
     
        // Do not forget to clean up the snapshot object.     CloseHandle (hProcessSnap); 
        return (bRet); 

      

  3.   

    注意WinNT不支持CreateToolHelp32Snapshot,Win98,Win2000可以。
      

  4.   

    CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)可以,
    但CreateToolhelp32Snapshot(TH32CS_SNAMODULE, 0)就不行了
    返回的错误信息是拒绝服务。我是在2000下写的?
    用的是C++BUILDER 3有问题吗??
      

  5.   

    跟权限有关吗?用AdjustTokenPrivileges再试试了.