Necesitaba encontrar la ruta completa de un archivo sabiendo solo el nombre del proceso y salio esto basándome en el codigo en C de Emerick Rogul.
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author: Naker90

 Script Function:
	Obtiene la ruta completa de un proceso en ejecucion

 Basado en el codigo en C de Emerick Rogul
 http://stackoverflow.com/questions/1933113/c-windows-how-to-get-process-path-from-its-pid

#ce ----------------------------------------------------------------------------
Func _GetFullPath($sProcessName)

	Const $sPROCESS_QUERY_INFORMATION = 0x0400
	Const $sPROCESS_VM_READ = 0x0010
	Const $sMAX_PATH = 500

	Local $sPID = ProcessExists($sProcessName)

	if $sPID = 0 then
		MsgBox(16, 'ERROR', 'El Proceso expecificado no esta en ejecución')
		Exit
	EndIf

	Local $sHandle = DllCall('Kernel32.dll','Ptr', 'OpenProcess','int', BitOR($sPROCESS_QUERY_INFORMATION, $sPROCESS_VM_READ), 'int', 0, 'int', $sPID)

	Local $sFileStruct = DllStructCreate('Wchar[' & $sMAX_PATH & ']')
	Local $sGetModuleFileNameExW = DllCall('Psapi.dll', 'Dword', 'GetModuleFileNameExW', 'Ptr', $sHandle[0], 'Ptr', 0, 'Ptr', DllStructGetPtr($sFileStruct), 'Dword', $sMAX_PATH)

	DllCall('Kernel32.dll','int', 'CloseHandle','Ptr', $sHandle[0])

	Local $sReturn = DllStructGetData($sFileStruct, 1)
	Return $sReturn

EndFunc
Ejemplo:

Código: Seleccionar todo

Llamada: _GetFullPath('Anotador Naker90.exe')
Retorna: C:\Users\Naker90\Desktop\Anotador Naker90.exe
Saludos
Skype: naker.noventa
Muy bueno.

Te corrijo algunas cositas :P

Func _GetFullPath($sProcessName)

   Local Const $sPROCESS_QUERY_INFORMATION = 0x0400
   Local Const $sPROCESS_VM_READ = 0x0010
   Local Const $sMAX_PATH = 32767

    Local $sPID = ProcessExists($sProcessName)

    if $sPID = 0 then
        MsgBox(16, 'ERROR', 'El Proceso expecificado no esta en ejecución')
        Return ''
    EndIf

    Local $sHandle = DllCall('Kernel32.dll','handle', 'OpenProcess','dword', BitOR($sPROCESS_QUERY_INFORMATION, $sPROCESS_VM_READ), 'bool', 0, 'dword', $sPID)
   ;verifica si openprocess funcionó

    Local $sFileStruct = DllStructCreate('wchar[' & $sMAX_PATH & ']')
    Local $sGetModuleFileNameExW = DllCall('Psapi.dll', 'Dword', 'GetModuleFileNameExW', 'handle', $sHandle[0], 'handle', 0, 'ptr', DllStructGetPtr($sFileStruct), 'Dword', $sMAX_PATH)
 ;verifica si funciono la llamada
    DllCall('Kernel32.dll','bool', 'CloseHandle','handle', $sHandle[0])

    Local $sReturn = DllStructGetData($sFileStruct, 1)
    Return $sReturn

EndFunc

Saludos
Imagen
@Pink
Func _GetFullPath($sProcessName)

   Local Const $sPROCESS_QUERY_INFORMATION = 0x0400
   Local Const $sPROCESS_VM_READ = 0x0010
   Local Const $sMAX_PATH = 32767

    Local $sPID = ProcessExists($sProcessName)

    if $sPID = 0 then
        MsgBox(16, 'ERROR', 'El Proceso expecificado no esta en ejecución')
        Return ''
    EndIf

    Local $sHandle = DllCall('Kernel32.dll','handle', 'OpenProcess','dword', BitOR($sPROCESS_QUERY_INFORMATION, $sPROCESS_VM_READ), 'bool', 0, 'dword', $sPID)
	If Not $sHandle[0] then
		MsgBox(16, 'ERROR', 'Hubo un arror abriendo el proceso')
		Return ''
	EndIf

    Local $sFileStruct = DllStructCreate('wchar[' & $sMAX_PATH & ']')
    Local $sGetModuleFileNameExW = DllCall('Psapi.dll', 'Dword', 'GetModuleFileNameExW', 'handle', $sHandle[0], 'handle', 0, 'ptr', DllStructGetPtr($sFileStruct), 'Dword', $sMAX_PATH)
	If @error then
		MsgBox(16, 'ERROR', 'Hubo un problema obteniendo la ruta con GetModuleFileNameExW')
		Return ''
	EndIf

    DllCall('Kernel32.dll','bool', 'CloseHandle','handle', $sHandle[0])

    Local $sReturn = DllStructGetData($sFileStruct, 1)
    Return $sReturn

EndFunc
Saludos
Skype: naker.noventa
Responder

Volver a “Fuentes”