Sign in to follow this  
Followers 0
stinger

Help: _WinAPI_GetCurrentProcess() return -1

4 posts in this topic

I've wrote a sample code to get my proc handle but dont know why it always return 0xffffffff

Here's my code

#include <WinAPI.au3>
$hwnd = _WinAPI_GetCurrentProcess()
$procid = _WinAPI_GetCurrentProcessID()
MsgBox(0, "Info", $hwnd)
MsgBox(0, "Info", $procid)

GetCurrentProcessID is working good but GetCurrentProcess does not work, there's no error. Am i missing something ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is a confusion in the description. _WinAPI_GetCurrentProcess() returns a pseudo handle of the current process, not a real handle.

#Include <WinAPI.au3>

$PID = _WinAPI_GetCurrentProcessID()
$hProcess = _WinAPI_GetCurrentProcess()
$Ret = DllCall('kernel32.dll', 'bool', 'DuplicateHandle', 'ptr', $hProcess, 'ptr', $hProcess, 'ptr', $hProcess, 'ptr*', 0, 'dword', 0, 'bool', 0, 'dword', 2)

ConsoleWrite('PID:           ' & $PID & @CR)
ConsoleWrite('Pseudo handle: ' & $hProcess & @CR)
ConsoleWrite('Real handle:   ' & $Ret[4] & @CR)
Edited by Yashied

Share this post


Link to post
Share on other sites

This is a confusion in the description. _WinAPI_GetCurrentProcess() returns a pseudo handle of the current process, not a real handle.

#Include <WinAPI.au3>

$PID = _WinAPI_GetCurrentProcessID()
$hProcess = _WinAPI_GetCurrentProcess()
$Ret = DllCall('kernel32.dll', 'bool', 'DuplicateHandle', 'ptr', $hProcess, 'ptr', $hProcess, 'ptr', $hProcess, 'ptr*', 0, 'dword', 0, 'bool', 0, 'dword', 2)

ConsoleWrite('PID:           ' & $PID & @CR)
ConsoleWrite('Pseudo handle: ' & $hProcess & @CR)
ConsoleWrite('Real handle:   ' & $Ret[4] & @CR)

Thanks alot for your reply.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

So... what's the difference to @AutoItPID?

Edit:

Reread the post and realized that you wanted to obtain the process handle :graduated:... and also that the "Delete" post does not seem to work.

Edited by KaFu

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0