1. Pacito Nefulda
  2. PowerBuilder
  3. Thursday, 3 January 2019 16:26 PM UTC

Can somebody help us resolve our problem with Kernel32 OpenProcess function which seems to be not working in Windows 10 but OK in Windows 7 environment. Why?

OpenProcess(1041 ,False, ll_process_list[li_cnt])

 

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 3 January 2019 16:44 PM UTC
  2. PowerBuilder
  3. # Permalink

You didn't tell us how you defined it. I checked the docs and it should be:


Function long OpenProcess(ulong dwDesiredAccess, boolean bInheritHandle, ulong dwProcessId) Library "kernel32.dll"

Did you check the return value?

Also, what access options does 1041 represent? 1041 is 411 in hex.

PROCESS_QUERY_INFORMATION (0x0400) is 1024.

 

Comment
There are no comments made yet.
Samuel Brognoli Accepted Answer Pending Moderation
  1. Thursday, 7 February 2019 10:54 AM UTC
  2. PowerBuilder
  3. # 1

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 ''

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 3 January 2019 17:08 PM UTC
  2. PowerBuilder
  3. # 2

Hi Pacito;

  This could be an issue in W10 around the "process access" rights that you have in the W10 O/S.

Try running your App (or the PB IDE for that matter) as "Admin".

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.