找回密码
 加入
搜索
查看: 4534|回复: 3

[AU3基础] 【已解决】 API ShellExecuteEx 打开一个快捷方式,并且返回其运行后的窗口句柄或PID

[复制链接]
发表于 2015-4-30 10:45:13 | 显示全部楼层 |阅读模式
本帖最后由 拉风晓晓 于 2015-5-13 12:44 编辑

不一定是可执行文件,帮助里面的_WinAPI_ShellExecuteEx
Return Value
Success : True.
Failure : False. 不能返回PID
发表于 2015-5-1 23:20:57 | 显示全部楼层
本帖最后由 李岸 于 2015-5-1 23:26 编辑
#include <WinAPIShellEx.au3>
#include <WinAPIProc.au3>
$sCmd = 'C:\Users\Administrator\Desktop\Play.lnk'
$sVerb = 'open'

$iCmdLen = StringLen($sCmd)
$iVerb = StringLen($sVerb)

$stCmd = DllStructCreate("wchar[" & $iCmdLen + 1 & "]")
$stVerb = DllStructCreate("wchar[" & $iVerb + 1 & "]")

DllStructSetData($stCmd, 1, $sCmd)
DllStructSetData($stVerb, 1, $sVerb)

$stINFO = DllStructCreate("ulong;ulong;long;ptr;ptr;ptr;ptr;long;long;ptr;ptr;long;ulong;long;long")

DllStructSetData($stINFO, 1, DllStructGetSize($stINFO))
DllStructSetData($stINFO, 2, BitOR(0x40, 0x400)) 
DllStructSetData($stINFO, 3, 0)
DllStructSetData($stINFO, 4, DllStructGetPtr($stVerb))
DllStructSetData($stINFO, 5, DllStructGetPtr($stCmd))
DllStructSetData($stINFO, 8, 1)
_WinAPI_ShellExecuteEx($stINFO)

$hProcess = DllStructGetData($stINFO, 15)
$PID = _WinAPI_GetProcessID($hProcess)
$hWnd = _GetHwndFromPID($PID)

Func _GetHwndFromPID($PID)
        $hWnd = 0
        $stPID = DllStructCreate("int")
        Do
                $winlist2 = WinList()
                For $i = 1 To $winlist2[0][0]
                        If $winlist2[$i][0] <> "" Then
                                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                                If DllStructGetData($stPID, 1) = $PID Then
                                        $hWnd = $winlist2[$i][1]
                                        ExitLoop
                                EndIf
                        EndIf
                Next
                Sleep(100)
        Until $hWnd <> 0
        Return $hWnd
EndFunc   ;==>_GetHwndFromPID
 楼主| 发表于 2015-5-6 14:08:35 | 显示全部楼层
今天我试过了,还是不行。感谢楼上回复,还没看懂,所以还要细看一下
发表于 2015-5-7 16:43:50 | 显示全部楼层
回复 3# 拉风晓晓
这个代码完全符合标题的要求!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 20:37 , Processed in 0.079593 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表