Hi All.
I am experiencing the same issue.
In my case the OpenProcess function is always returning 0 (zero) even running with admin rights.
It works fine on Win7 (even without admin rights) but does not work on Win10.
I've tried also changing the first parameter to 1024 and 1041 as I saw in your examples.
This is the code that is working in win7. I'm using PB2017 R3 (classic). Any help, please?
/*Windows API functions to handle windows process*/
FUNCTION BOOLEAN EnumProcesses(REF ULONG process_id[2048], ULONG array_size,REF ULONG bytes) LIBRARY "psapi.dll"
FUNCTION ULONG OpenProcess(ULONG access_flag, BOOLEAN inheritence_flag, ULONG process_id) LIBRARY "kernel32.dll"
FUNCTION BOOLEAN EnumProcessModules(ULONG process_handle, REF ULONG module_handles[2048], ULONG array_size, REF ULONG bytes) LIBRARY "psapi.dll"
FUNCTION ULONG GetModuleBaseNameA(ULONG process_handle, ULONG module_handle,REF STRING base_name, ULONG buffer_size) LIBRARY "psapi.dll" alias for "GetModuleBaseNameA;Ansi"
FUNCTION BOOLEAN CloseHandle(ULONG process_handle) LIBRARY "kernel32.dll"
// This function returns the Process Name for the specified Process ID.
STRING ls_BaseName
ULONG lul_ModuleArray[2048]
ULONG lul_ArraySize=8192
ULONG lul_BufferSize=1024
ULONG lul_ProcessHandle
ULONG lul_BufferLength
ULONG lul_Bytes
INTEGER li_Index
CONSTANT LONG PROCESS_QUERY_INFORMATION_PROCESS_VM_READ_SYNCHRONIZE= 1049616
// Get process handle for specified Process ID.
lul_ProcessHandle = OpenProcess( PROCESS_QUERY_INFORMATION_PROCESS_VM_READ_SYNCHRONIZE , FALSE,aul_ProcessID)
IF IsNull(lul_ProcessHandle) THEN lul_ProcessHandle = 0
// If we have a process handle, then continue.
IF lul_ProcessHandle > 0 THEN
// Get the module handles for the specified process handle.
IF EnumProcessModules (lul_ProcessHandle, lul_ModuleArray, lul_ArraySize, lul_Bytes) THEN
li_Index = 0
Do
li_Index ++
ls_BaseName = Space(lul_BufferSize) // initialize for function call
// Get name of process for specified handle.
lul_BufferLength = GetModuleBaseNameA(lul_ProcessHandle,lul_ModuleArray[li_Index], ls_BaseName, lul_BufferSize)
IF lul_BufferLength > 0 THEN
ls_BaseName = Trim(ls_BaseName)
RETURN ls_BaseName
END IF
LOOP UNTIL lul_ModuleArray[li_Index] <> 0
END IF
END IF
CloseHandle(lul_ProcessHandle)
RETURN ''