#Requires AutoHotkey v2.0
MsgBox ReadProcessStdOut("cscript //nologo " A_WinDir "\System32\slmgr.vbs /xpr")
MsgBox ReadProcessStdOut("ipconfig")
ReadProcessStdOut(cmd, encoding := "cp0") {
sa := Buffer(24)
NumPut("uint", sa.Size, sa)
NumPut("ptr", 0, "uint", 1, sa, 8)
if !DllCall("CreatePipe", "ptr*", &hReadPipe := 0, "ptr*", &hWritePipe := 0, "ptr", sa, "uint", 0)
throw OSError()
DllCall("SetHandleInformation", "ptr", hReadPipe, "uint", 1, "uint", 0)
si := Buffer(104, 0)
NumPut("uint", si.Size, si)
NumPut("uint", 0x101, si, 60)
NumPut("ptr", hWritePipe, si, 88)
if !DllCall("CreateProcessW", "ptr", 0, "str", cmd, "ptr", 0, "ptr", 0, "int", true, "uint", 0, "ptr", 0, "ptr", 0, "ptr", si, "ptr", pi := Buffer(24)) {
DllCall("CloseHandle", "ptr", hWritePipe)
DllCall("CloseHandle", "ptr", hReadPipe)
throw OSError()
}
DllCall("CloseHandle", "ptr", NumGet(pi, "ptr"))
DllCall("CloseHandle", "ptr", NumGet(pi, 8, "ptr"))
DllCall("CloseHandle", "ptr", hWritePipe)
stdout := ""
while DllCall("ReadFile", "ptr", hReadPipe, "ptr", buf := Buffer(4096), "uint", buf.Size, "uint*", &lpNumberOfBytesRead := 0, "ptr", 0) && lpNumberOfBytesRead
stdout .= StrGet(buf, lpNumberOfBytesRead, encoding)
DllCall("CloseHandle", "ptr", hReadPipe)
return stdout
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)