| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 827 人关注过本帖
标题:API 取进程名,错误代码 299 怎么解决
只看楼主 加入收藏
Ez330阿牛
Rank: 2
等 级:论坛游民
帖 子:42
专家分:14
注 册:2014-3-5
结帖率:11.11%
收藏
已结贴  问题点数:5 回复次数:1 
API 取进程名,错误代码 299 怎么解决
程序代码:
  Dim ModuleMsg As API声明.MODULEENTRY32, hSnapShot As Long
        hSnapShot = API声明.CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID)  '建立进程快照
        If hSnapShot > 0 Then
            API声明.CopyMemory_Long ModuleMsg.dwSize, Len(ModuleMsg), 4
            If API声明.Module32First(hSnapShot, ModuleMsg) > 0 Then '获取模块信息
                With ModuleMsg
                    GetPoocessOfByPId = .szModule
                End With
            End If
        End If
        Debug.Print API声明.GetLastError
        API声明.CloseHandle hSnapShot


程序代码:
Public Function GetProcessPathByProcessID(PID As Long) As String
    On Error GoTo Z
    Dim cbNeeded As Long
    Dim szBuf(1 To 250) As Long
    Dim Ret As Long
    Dim szPathName As String
    Dim nSize As Long
    Dim hProcess As Long
    hProcess = OpenProcess(&H400 Or &H10, 0, PID)
    If hProcess <> 0 Then
        Ret = EnumProcessModules(hProcess, szBuf(1), 250, cbNeeded)
        
        If Ret <> 0 Then
            Debug.Print GetLastError, "e"
            szPathName = Space(260)
            nSize = 500
            Ret = GetModuleFileNameExA(hProcess, szBuf(1), szPathName, nSize)
            GetProcessPathByProcessID = Left(szPathName, Ret)
        End If
    End If
    Ret = CloseHandle(hProcess)
    If GetProcessPathByProcessID = "" Then
        Debug.Print GetLastError
        GetProcessPathByProcessID = "SYSTEM"
    End If
    Exit Function
Z:
End Function

我用了两种不同的办法,取进程名,都取不到,而且都是返回 299 ,求解决,我百度不到
搜索更多相关主题的帖子: color 
2014-09-27 14:06
茅十八
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:35
专家分:123
注 册:2014-3-11
收藏
得分:5 
Option Explicit

Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Const TH32CS_SNAPPROCESS As Long = &H2

Private Declare Function Process32First Lib "kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32.dll" (ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Const MAX_PATH As Long = 260




Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * MAX_PATH
End Type



'枚举进程 方法一
Private Sub Command1_Click()
    Dim hSnap As Long
    hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)   '获取进程列表的快照
   
    Dim PE32 As PROCESSENTRY32, bMore As Boolean
    PE32.dwSize = LenB(PE32)    '要先设置结构大小
   
    If hSnap Then
        bMore = Process32First(hSnap, PE32)
    Else
        MsgBox "调用CreateToolhelp32Snapshot失败"
    End If

    While bMore
        List1.AddItem Left(PE32.szExeFile, InStr(PE32.szExeFile, Chr$(0)) - 1) & Space(4) & "进程ID:" & PE32.th32ProcessID
        'If PE32.szExeFile = "欲搜索的进程名" Then GoTo SS:
        '继续枚举
        bMore = Process32Next(hSnap, PE32)
    Wend
    'SS
    CloseHandle hSnap
End Sub

'枚举进程 方法二
Private Sub Command2_Click()
    Dim a_pidProcess(0 To 1023) As Long, cbNeeded As Long, index As Long
    If EnumProcesses(a_pidProcess(0), 1024, cbNeeded) Then
        For index = 0 To cbNeeded / 4
            List2.AddItem "进程ID:" & a_pidProcess(index)
            '如果你愿意,可以通过EnumProcessModules继续枚举hModules
        Next
    Else
        MsgBox "枚举进程失败"
    End If
End Sub


[ 本帖最后由 茅十八 于 2014-9-28 00:46 编辑 ]

个人QQ:1789851851,有学习问题,欢迎找我讨论,另外Win32 SDK开发群:179492890
2014-09-27 23:56
快速回复:API 取进程名,错误代码 299 怎么解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023491 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved