I updated AHK to the newest version now and you script doesnt work any longer?!
I think this should work? But it says: "Error Call To Nonexistent Function" Specifically: COM_Init()
Code:
sCmd := "ipconfig /all"
;sDir := ""
;sInput := ""
MsgBox, % StdCreateProcess(sCmd, sDir, sInput) ; StdCreateProcessCOM(sCmd, sDir, sInput)
StdCreateProcess(sCmd, sDir = "", sInput = "")
{
If sInput <>
CreatePipe(hStdInRd , hStdInWr ), SetHandleInformation(hStdInRd )
CreatePipe(hStdOutRd, hStdOutWr), SetHandleInformation(hStdOutWr)
VarSetCapacity(pi, 16, 0)
NumPut(VarSetCapacity(si, 68, 0), si) ; size of si
NumPut(0x100 , si, 44) ; STARTF_USESTDHANDLES
NumPut(hStdInRd , si, 56) ; hStdInput
NumPut(hStdOutWr, si, 60) ; hStdOutput
NumPut(hStdOutWr, si, 64) ; hStdError
If Not DllCall("CreateProcess", "Uint", 0, "Uint", &sCmd, "Uint", 0, "Uint", 0, "int", True, "Uint", 0x08000000, "Uint", 0, "Uint", sDir ? &sDir : 0, "Uint", &si, "Uint", &pi) ; bInheritHandles and CREATE_NO_WINDOW
ExitApp
CloseHandle(NumGet(pi,0)), CloseHandle(NumGet(pi,4))
If sInput <>
StdInput( sInput , hStdInRd , hStdInWr )
StdOutput(sOutput, hStdOutRd, hStdOutWr)
Return sOutput
}
StdCreateProcessCOM(sCmd, sDir = "", sInput = "")
{
COM_Init()
pwsh := COM_CreateObject("WScript.Shell")
sDir ? COM_Invoke(pwsh, "CurrentDirectory=", sDir) : ""
pexec:= COM_Invoke(pwsh, "Exec", sCmd)
WinWaitActive, ahk_class ConsoleWindowClass,, 1
WinHide
If sInput <>
pin := COM_Invoke(pexec, "StdIn"), COM_Invoke(pin, "Write", sInput), COM_Invoke(pin, "Close"), COM_Release(pin)
pout := COM_Invoke(pexec, "StdOut") ; perr := COM_Invoke(pexec, "StdErr")
Loop
If COM_Invoke(pout, "AtEndOfStream")=0
sOutput .= COM_Invoke(pout, "ReadLine") . "`r`n"
Else Break
COM_Invoke(pout, "Close"), COM_Release(pout)
Loop
If COM_Invoke(pexec, "Status")=0
Sleep, 100
Else Break
; COM_Invoke(pexec, "Terminate")
COM_Release(pexec)
COM_Release(pwsh)
COM_Term()
Return sOutput
}
StdInput(ByRef sInput, hStdInRd, hStdInWr)
{
CloseHandle(hStdInRd)
WriteFile(hStdInWr, &sInput, StrLen(sInput))
CloseHandle(hStdInWr)
}
StdOutput(ByRef sOutput, hStdOutRd, hStdOutWr)
{
CloseHandle(hStdOutWr)
VarSetCapacity(sTemp, 4095)
Loop
If nSize:=ReadFile(hStdOutRd, &sTemp, 4095)
NumPut(0, sTemp, nSize, "char"), VarSetCapacity(sTemp, -1), sOutput .= sTemp
Else Break
CloseHandle(hStdOutRd)
}
CreatePipe(ByRef hRead, ByRef hWrite)
{
Return DllCall("CreatePipe", "UintP", hRead, "UintP", hWrite, "Uint", 0, "Uint", 0)
}
ReadFile(hFile, pBuffer, nSize)
{
If DllCall("ReadFile" , "Uint", hFile, "Uint", pBuffer, "Uint", nSize, "UintP", nSize, "Uint", 0)
Return nSize
}
WriteFile(hFile, pBuffer, nSize)
{
If DllCall("WriteFile", "Uint", hFile, "Uint", pBuffer, "Uint", nSize, "UintP", nSize, "Uint", 0)
Return nSize
}
GetHandleInformation(Handle)
{
If DllCall("GetHandleInformation", "Uint", Handle, "UintP", nFlags)
Return nFlags
}
SetHandleInformation(Handle, nFlags = 1) ; HANDLE_FLAG_INHERIT = 1
{
Return DllCall("SetHandleInformation", "Uint", Handle, "Uint", nFlags, "Uint", nFlags)
}
CloseHandle(Handle)
{
Return DllCall("CloseHandle", "Uint", Handle)
}