(Solved) How to hide cmd window?

Get help with using AutoHotkey and its commands and hotkeys
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

(Solved) How to hide cmd window?

26 Jul 2014, 02:29

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   
Last edited by ahcahc on 27 Jul 2014, 04:19, edited 1 time in total.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: How to hide cmd window?

26 Jul 2014, 03:41

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
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: How to hide cmd window?

26 Jul 2014, 03:57

Thank you very much....

Return to “Ask For Help”

Who is online

Users browsing this forum: barbaque, Bing [Bot], Google [Bot] and 254 guests