Code: Alles auswählen
Prototype pGetModuleFileNameEx_(hProcess.i, hModule.i, lpFilename.i, nSize.l)
If OpenLibrary(0, "psapi.dll")
  Global GetModuleFileNameEx_.pGetModuleFileNameEx_ = GetFunction(0, "GetModuleFileNameExW")
EndIf
If Not GetModuleFileNameEx_ : End : EndIf
Procedure.s FormatMessage(ErrorNumber.l)
  Protected *Buffer, len.l, result.s
  len = FormatMessage_(#FORMAT_MESSAGE_ALLOCATE_BUFFER|#FORMAT_MESSAGE_FROM_SYSTEM,0,ErrorNumber,0,@*Buffer,0,0)
  If len
    result = PeekS(*Buffer, len - 2)
    LocalFree_(*Buffer)
    ProcedureReturn result
  Else
    ProcedureReturn "Errorcode: " + Hex(ErrorNumber)
  EndIf
EndProcedure
Procedure.s GetProcessnameByPID(lPID.l)
  Protected hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, 0, lPID)
  If hProcess
    Debug "Process Handle: " + Str(hProcess)
    Protected szPath.s = Space(4096)
    If GetModuleFileNameEx_(hProcess, 0, @szPath, 4096)
      Debug "ModuleFileName: " + szPath
    Else
      Debug "FileName Error: " + FormatMessage(GetLastError_())
    EndIf
    CloseHandle_(hProcess)      
    ProcedureReturn szPath
  Else
    Debug "OpenProcess Error" + FormatMessage(GetLastError_())
  EndIf
EndProcedure
Debug GetProcessnameByPID(500) ;PID eines Processes ermittelt mit Process Explorer XP
Code: Alles auswählen
Prototype pGetModuleFileNameEx_(hProcess.i, hModule.i, lpFilename.i, nSize.l)
If OpenLibrary(0, "psapi.dll")
  Global GetModuleFileNameEx_.pGetModuleFileNameEx_ = GetFunction(0, "GetModuleFileNameExW")
EndIf
If Not GetModuleFileNameEx_ : End : EndIf
Procedure.s FormatMessage(ErrorNumber.l)
  Protected *Buffer, len.l, result.s
  len = FormatMessage_(#FORMAT_MESSAGE_ALLOCATE_BUFFER|#FORMAT_MESSAGE_FROM_SYSTEM,0,ErrorNumber,0,@*Buffer,0,0)
  If len
    result = PeekS(*Buffer, len - 2)
    LocalFree_(*Buffer)
    ProcedureReturn result
  Else
    ProcedureReturn "Errorcode: " + Hex(ErrorNumber)
  EndIf
EndProcedure
Procedure.s GetProcessnameByPID(lPID.l)
  Protected hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, 0, lPID)
  If hProcess
    Debug "Process Handle: " + Str(hProcess)
    Protected szPath.s = Space(4096)
    If GetModuleFileNameEx_(hProcess, 0, @szPath, 4096)
      Debug "ModuleFileName: " + szPath
    Else
      Debug "FileName Error: " + FormatMessage(GetLastError_())
    EndIf
    CloseHandle_(hProcess)      
    ProcedureReturn szPath
  Else
    Debug "OpenProcess Error" + FormatMessage(GetLastError_())
  EndIf
EndProcedure
Program = RunProgram("cmd.exe", "/k echo hallo world", "", #PB_Program_Open)
If IsProgram(Program)
  Debug "ProcessID     : " + Str(ProgramID(Program))
  GetProcessnameByPID(ProgramID(Program))
  CloseProgram(Program)
EndIf




