quindi questa è la mia soluzione:
;******************
;ALLOCATING CONSOLE
;******************
; cmd calls hidden
global cPid
DetectHiddenWindows, on
Run, %comspec% /k ,,Hide UseErrorLevel,cPid
WinWait, ahk_pid %cPid%,, 1
DllCall("AttachConsole","uint",cPid)
hCon:=DllCall("CreateFile","str","CONOUT$","uint",0xC0000000,"uint",7,"uint",0,"uint",3,"uint",0,"uint",0)
;******* GET PRINTER NAMES **********
AllPrintersNameClearArray := strSplit(StrReplace(StrReplace(StrReplace(StrReplace("|" StrReplace(StrReplace(StrReplace(RunWaitOne("wmic printer get name")," ","")," `r",""),"`r",""),"|NAME`n",""),"`n","|"),"||","",All),"|","`n"),"`n")
RunWaitOne(command) {
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(command)
strStdOut := ""
while, !objExec.StdOut.AtEndOfStream
strStdOut := objExec.StdOut.ReadAll()
return %strStdOut%
}
; **** Clean at the end *****
Finish:
DllCall("CloseHandle", "uint", hCon)
DllCall("FreeConsole")
Process, Close, %cPid%
ExitApp
return