PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: QueryFullProcessImageName  (Read 170 times)

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
QueryFullProcessImageName
« on: August 02, 2017, 11:28:55 AM »

Why i cant use QueryFullProcessImageName?

My FF_AppStart
Code: [Select]
#Define WIN32_WINNT = 0x0600
#Include Once "win/WinBase.bi"

Form1
Code: [Select]

'Declare Function QueryFullProcessImageName Lib "kernel32.dll" Alias "QueryFullProcessImageNameA" (ByVal ProcessHandle as HANDLE, ByVal  ProcessFlags as DWORD, ByVal Exename as LPSTR, ByVal BufferLength as PDWORD) as WINBOOL

'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     as Long, _      ' index in Control Array
                                   hWndForm         as HWnd, _      ' handle of Form
                                   hWndControl      as HWnd, _      ' handle of Control
                                   idButtonControl  as Long   _     ' identifier of button
                                   ) as Long
Dim Ret as Long

   'Ret = QueryFullProcessImageName(0, 0, 0, 0)

Dim hProcess as HANDLE

   'hProcess = OpenProcess(0, 0, 0)


   Function = 0   ' change according to your needs
End Function

If you comment out hProcess = OpenProcess(0, 0, 0) the program compile's with Ret = QueryFullProcessImageName(0, 0, 0, 0) it wont.
The compiler says 'The error 41: Variable not declared , QueryFullProcessImageName ...
I forgot to add something?.
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #1 on: August 02, 2017, 11:32:56 AM »

#Define WIN32_WINNT = 0x0600 must be #Define WIN32_WINNT = &h0602.

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: QueryFullProcessImageName
« Reply #2 on: August 02, 2017, 11:38:27 AM »

Strange the error wont go away, the compiler still says  'error 41: Variable not declared, QueryFullProcessImageName
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #3 on: August 02, 2017, 11:41:58 AM »

Probably it is being ignored because WinBase.bi has already been included. The equate must be placed before any other include, e.g. before "windows.bi", that already includes WinBase.bi.

BTW it must be #Define WIN32_WINNT &h0602, without the equal sign.
« Last Edit: August 02, 2017, 11:44:45 AM by Josť Roca »
Logged

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: QueryFullProcessImageName
« Reply #4 on: August 02, 2017, 11:48:39 AM »


This is my FF_AppStart file
Code: [Select]
#Lang "FB"

#Include Once "windows.bi"
#Include Once "win/commctrl.bi"  ' needed for WinXP Theme support
#Include Once "win/commdlg.bi"
#Include Once "win/richedit.bi"

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------

'#Define Unicode
#Define WIN32_WINNT &h0602
#Include Once "win/winsock2.bi"
#Include Once "win/Iphlpapi.bi"
#Include Once "win/WinBase.bi"     

And the calling code in a module file 'exefrompid.inc'
Code: [Select]
'Declare Function QueryFullProcessImageName Lib "kernel32.dll" Alias "QueryFullProcessImageNameA" (ByVal ProcessHandle as HANDLE, ByVal ProcessFlags as DWORD, ByVal Exename as LPSTR, ByVal BufferLength as PDWORD) as WINBOOL


Function ProcessPathByPID(ByVal PID as Long) as String

 If PID = 0 Then ProcessPathByPID = "[System Idle Process]": Exit Function
  If PID = 4 Then ProcessPathByPID = "[System Process]": Exit Function
                                       
                                    '   Const PROCESS_QUERY_LIMITED_INFORMATION = &H1000
Dim hProcess as HANDLE
    hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, PID)
 ' hProcess = OpenProcess(0, 0, 0)
 If hProcess = 0 Then
    GetApiErrorInfo(GetLastError), "hProcess1  " & PID
    ProcessPathByPID = "[Unknown Process]": Exit Function
 End If
 
Dim i as Integer: i = 1024
Dim Exename as String : Exename = Space(i)
Dim Buf as Long: Buf = 1024
                                   ' Const PROCESS_NAME_NATIVE = &H1   'The name should use the native system path format.
                                   ' 0                                 'The name should use the Win32 path format.
     
Dim Ret as Long
    Ret = QueryFullProcessImageName(hProcess, 0, Exename, @Buf)
 If Ret = 0 Then
    GetApiErrorInfo(GetLastError), "hProcess2  " & PID
    Ret = CloseHandle(@hProcess)
    ProcessPathByPID = "[Unknown Process]": Exit Function
 Else
    ProcessPathByPID = Trim$(Exename)
'    ProcessPathByPID = Left$(Exename, i)
    Ret = CloseHandle(@hProcess)
 End If

'Print ProcessPathByPID

End Function

Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #5 on: August 02, 2017, 12:01:00 PM »

Use

Code: [Select]
#Lang "FB"

'#Define Unicode
#Define WIN32_WINNT &h0602
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"  ' needed for WinXP Theme support
#Include Once "win/commdlg.bi"
#Include Once "win/richedit.bi"

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------

#Include Once "win/winsock2.bi"
#Include Once "win/Iphlpapi.bi"

You don't need to include WinBase.bi because it is already included by Windows.bi.

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: QueryFullProcessImageName
« Reply #6 on: August 02, 2017, 12:11:59 PM »

That dident help, the compiler still says  'error 41: Variable not declared, QueryFullProcessImageName

This is my FF_AppStart file
Code: [Select]
#Lang "FB"

'#Define Unicode
#Define WIN32_WINNT &h0602
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"  ' needed for WinXP Theme support
#Include Once "win/commdlg.bi"
#Include Once "win/richedit.bi"

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------

#Include Once "win/winsock2.bi"
#Include Once "win/Iphlpapi.bi"


And the calling code in Form1

Code: [Select]
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     as Long, _      ' index in Control Array
                                   hWndForm         as HWnd, _      ' handle of Form
                                   hWndControl      as HWnd, _      ' handle of Control
                                   idButtonControl  as Long   _     ' identifier of button
                                   ) as Long
Dim Ret as Long

   Ret = QueryFullProcessImageName(0, 0, 0, 0)

Dim hProcess as HANDLE

  ' hProcess = OpenProcess(0, 0, 0)

  '  Ret = GetExtendedTcpTable(0, 0, 0, 0, 0, 0)


   Function = 0   ' change according to your needs
End Function

« Last Edit: August 02, 2017, 12:16:13 PM by jermy »
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #7 on: August 02, 2017, 12:22:11 PM »

I have checked the WinBase.bi file and that function is wrapped between

Code: [Select]
#if _WIN32_WINNT = &h0602
declare function LoadPackagedLibrary(byval lpwLibFileName as LPCWSTR, byval Reserved as DWORD) as HMODULE
const PROCESS_NAME_NATIVE = &h00000001
declare function QueryFullProcessImageNameA(byval hProcess as HANDLE, byval dwFlags as DWORD, byval lpExeName as LPSTR, byval lpdwSize as PDWORD) as WINBOOL
declare function QueryFullProcessImageNameW(byval hProcess as HANDLE, byval dwFlags as DWORD, byval lpExeName as LPWSTR, byval lpdwSize as PDWORD) as WINBOOL
#endif

Therefore, it must be #Define _WIN32_WINNT &h0602, with a leading underscore, not #Define WIN32_WINNT &h0602.

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: QueryFullProcessImageName
« Reply #8 on: August 02, 2017, 12:38:12 PM »

#Define _WIN32_WINNT &h0602

the comlpiler says  error 14: Expected identifier, found 'CERT_NAME_BLOB' in 'certificateNames as CERT_NAME_BLOB ptr'
and error 14: Expected identifier, found 'CRYPT_HASH_BLOB' in 'certBlob as CRYPT_HASH_BLOB'

FF_AppStart file
Code: [Select]
#Lang "FB"

'#Define Unicode
#Define _WIN32_WINNT &h0602
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"  ' needed for WinXP Theme support
#Include Once "win/commdlg.bi"
#Include Once "win/richedit.bi"

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------
' #Define _WIN32_WINNT &h0602
#Include Once "win/winsock2.bi"
#Include Once "win/Iphlpapi.bi"

That wont compiler, try the attachment i cant get it to work.
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #9 on: August 02, 2017, 12:46:36 PM »

Wincrypt.bi needs to be included. Use:

Code: [Select]
'#Define Unicode
#Define _WIN32_WINNT &h0602
#Include Once "windows.bi"
#Include Once "win/commctrl.bi"  ' needed for WinXP Theme support
#Include Once "win/commdlg.bi"
#Include Once "win/richedit.bi"

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------
#Include Once "win/wincrypt.bi"
#Include Once "win/winsock2.bi"
#Include Once "win/Iphlpapi.bi"


PRINT
PRINT "Press any key..."
SLEEP

jermy

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 15
Re: QueryFullProcessImageName
« Reply #10 on: August 02, 2017, 12:51:49 PM »

Thank you josť,

how did you find out?.
Logged

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2732
    • Josť Roca Software
Re: QueryFullProcessImageName
« Reply #11 on: August 02, 2017, 01:00:09 PM »

Searching. I did a search of the include files for CERT_NAME_BLOB and it is defined in wincrypt.bi.