Page 1 of 1

(Solved) How to hide cmd window?

Posted: 26 Jul 2014, 02:29
by ahcahc
Hi,

How do I hide the command prompt window that shows up when I run the following script (or prevent it from ever showing up)?

Code: Select all

objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec("cmd /c ping -n 3 -w 1000 www.google.com")
While !objExec.Status
	Sleep 100
strLine := objExec.StdOut.ReadAll()	;read the output at once
msgbox % strLine   

Re: How to hide cmd window?

Posted: 26 Jul 2014, 03:41
by Coco
Option 1:

Code: Select all

dhw := A_DetectHiddenWindows
DetectHiddenWindows On
Run "%ComSpec%" /k,, Hide, pid
while !(hConsole := WinExist("ahk_pid" pid))
	Sleep 10
DllCall("AttachConsole", "UInt", pid)
DetectHiddenWindows %dhw%
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec("cmd /c ping -n 3 -w 1000 www.google.com")
While !objExec.Status
    Sleep 100
strLine := objExec.StdOut.ReadAll() ;read the output at once
msgbox % strLine
DllCall("FreeConsole")
Process Exist, %pid%
if (ErrorLevel == pid)
	Process Close, %pid%
return
Option 2: (Shows/fashes the window quickly)

Code: Select all

DllCall("AllocConsole")
hConsole := DllCall("GetConsoleWindow")
WinWait % "ahk_id " hConsole
WinHide
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec("cmd /c ping -n 3 -w 1000 www.google.com")
While !objExec.Status
    Sleep 100
strLine := objExec.StdOut.ReadAll() ;read the output at once
msgbox % strLine
DllCall("FreeConsole")
return

Re: How to hide cmd window?

Posted: 26 Jul 2014, 03:57
by ahcahc
Thank you very much....