【已解决】 API ShellExecuteEx 打开一个快捷方式,并且返回其运行后的窗口句柄或PID
本帖最后由 拉风晓晓 于 2015-5-13 12:44 编辑不一定是可执行文件,帮助里面的_WinAPI_ShellExecuteEx
Return Value
Success : True.
Failure : False. 不能返回PID 本帖最后由 李岸 于 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
If $winlist2[$i] <> "" Then
DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i], "ptr", DllStructGetPtr($stPID))
If DllStructGetData($stPID, 1) = $PID Then
$hWnd = $winlist2[$i]
ExitLoop
EndIf
EndIf
Next
Sleep(100)
Until $hWnd <> 0
Return $hWnd
EndFunc ;==>_GetHwndFromPID 今天我试过了,还是不行。感谢楼上回复,还没看懂,所以还要细看一下 回复 3# 拉风晓晓
这个代码完全符合标题的要求!
页:
[1]