Code: Select all
MsgBox, % Clipboard := CmdRet("wmic product get name, version, vendor")
CmdRet(sCmd, cp := "cp866")
{
static STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
DllCall("CreatePipe", PtrP, hPipeRead, PtrP, hPipeWrite, UInt, 0, UInt, 0)
DllCall("SetHandleInformation", Ptr, hPipeWrite, UInt, 1, UInt, 1)
VarSetCapacity(pi, A_PtrSize*2 + 4*2, 0)
VarSetCapacity(si, sisize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
NumPut(sisize, si)
NumPut(STARTF_USESTDHANDLES, si, A_PtrSize*4 + 4*7)
NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*3)
NumPut(hPipeWrite, si, A_PtrSize*4 + 4*8 + A_PtrSize*4)
if !DllCall("CreateProcess", UInt, 0, Ptr, &sCmd, UInt, 0, UInt, 0, Int, true
, UInt, CREATE_NO_WINDOW, UInt, 0, UInt, 0, Ptr, &si, Ptr, &pi) {
DllCall("CloseHandle", Ptr, hPipeRead)
DllCall("CloseHandle", Ptr, hPipeWrite)
MsgBox, CreateProcess is failed
Return
}
DllCall("CloseHandle", Ptr, hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", Ptr, hPipeRead, Ptr, &sTemp, UInt, 4096, UIntP, nSize, UInt, 0)
sOutput .= StrGet(&sTemp, nSize, cp)
DllCall("CloseHandle", Ptr, NumGet(pi, 0))
DllCall("CloseHandle", Ptr, NumGet(pi, A_PtrSize))
DllCall("CloseHandle", Ptr, hPipeRead)
Return sOutput
}