Local Const $tagSTARTUPINFO="int Size;ptr Reserved1;ptr Desktop;ptr Title;int X;int Y;int XSize;int YSize;int XCountChars;" & _
"int YCountChars;int FillAttribute;int Flags;short ShowWindow;short Reserved2;ptr Reserved3;int StdInput;" & _
"int StdOutput;int StdError"
Local Const $tagPROCESS_INFORMATION="hwnd hProcess;hwnd hThread;int ProcessID;int ThreadID"
Local Const $SW_SHOW=1
Func _UID_CreateProcess($sCommand,$sDir,$ShowMode=$SW_SHOW)
;参数1:命令行;参数2:运行路径;参数3:显示模式,默认是显示
Local $pCommand, $tCommand, $pDir, $tDir, $aResult
Local $SI=DllStructCreate($tagSTARTUPINFO)
Local $PI=DllStructCreate($tagPROCESS_INFORMATION)
Local $pSI=DllStructGetPtr($SI) ;获取结构指针
Local $pPI=DllStructGetPtr($PI)
Local Const $STARTF_USESHOWWINDOW=1
DllStructSetData($SI,"Size",DllStructGetSize($SI)) ;必须步骤,初始化结构的大小
DllStructSetData($SI,"ShowWindow",$ShowMode) ;显示模式
DllStructSetData($SI,"Flags",$STARTF_USESHOWWINDOW) ;使用ShowWindow元素
If $sCommand <> "" Then
$tCommand = DllStructCreate("char Text[" & StringLen($sCommand) + 1 & "]")
$pCommand = DllStructGetPtr($tCommand)
DllStructSetData($tCommand, "Text", $sCommand)
EndIf
If $sDir <> "" Then
$tDir = DllStructCreate("char Text[" & StringLen($sDir) + 1 & "]")
$pDir = DllStructGetPtr($tDir)
DllStructSetData($tDir, "Text", $sDir)
EndIf
; $aResult = DllCall("Kernel32.dll", "int", "CreateProcess", "ptr", $pAppName, "ptr", $pCommand, "ptr", 0, "ptr", 0, _
; "int", false, "int", 0, "ptr", 0, "ptr", $pDir, "ptr", $pSI, "ptr", $pPI)
$aResult = DllCall("Kernel32.dll", "int", "CreateProcess", "ptr", 0, "ptr", $pCommand, "ptr", 0, "ptr", 0, _
"int", false, "int", 0, "ptr", 0, "ptr", $pDir, "ptr", $pSI, "ptr", $pPI)
If @error Then Return SetError(@error, 0, False)
Return $aResult[0] <> 0
EndFunc