/2014/08/18/Run-a-Windows-executable-with-a-hidden-console-window/
{"item":{"status":"visible","url":"\/2014\/08\/18\/Run-a-Windows-executable-with-a-hidden-console-window\/","trash":"","name":"Run-a-Windows-executable-with-a-hidden-console-window","parent":"","title":"Run a Windows executable with a hidden console window","date":"2014-08-18 22:50:15","filepath":"posts\/20140818_Run-a-Windows-executable-with-a-hidden-console-window.xml.json","type":"post","content":"<p><img style=\"float: left; margin-left: 10px; margin-right: 10px;\" src=\"http:\/\/www.8bitrobot.com\/media\/uploads\/2012\/01\/gear.png\" alt=\"\" width=\"60\" height=\"64\" \/>You may find running a console application in the background with the big black console window hidden is difficult on Windows.<\/p>\n<p>Here is a solution that will even work for non-console apps (window exe's). But be careful since you will have to use the task manager to kill applications that don't close on their own.<\/p>\n<p>The script arguments is the command you want to run. For example:<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-family: 'courier new', courier;\">> hide.vbs \"C:\\Windows\\System32\\makecab.exe\" data.txt out.cab<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-family: 'courier new', courier;\">> hide.vbs notepad.exe<\/span><\/p>\n<p>Using the script allows the creation of shortcut files to specific actions by tools (batch files, ImageMagick, etc).<\/p>\n<p><strong>Quick Demo:<\/strong><\/p>\n<ol>\n<li>Save the code to hide.vbs (<a href=\"http:\/\/www.8bitrobot.com\/media\/uploads\/hide.txt\">download here<\/a>)<\/li>\n<li>Create a shortcut to hide.vbs (right click, drag to location, select create shortcut)<\/li>\n<li>Edit the shortcut target: <br \/><span style=\"font-family: 'courier new', courier;\">C:\\hide.vbs \"C:\\Windows\\System32\\makecab.exe\" \"C:\\hide.vbs\" trash.cab<\/span><\/li>\n<li>Double click on the shortcut and you will see a trash.cab file created without seeing the console window (try a shortcut directly to makecab.exe to see how it normally behaves).<\/li>\n<\/ol>\n<p><strong><a href=\"http:\/\/www.8bitrobot.com\/media\/uploads\/hide.txt\">Here is the script source<\/a>:<\/strong><\/p>\n<pre style=\"font-family: 'courier new', courier;\">If WScript.Arguments.Count < 1 Then\n MsgBox(\"Error: Missing command arguments\")\n WScript.Quit\nEnd If\n\nDim argStr\nSet objSWbemServices = GetObject(\"WinMgmts:Root\\Cimv2\") \nSet colProcess = objSWbemServices.ExecQuery(\"Select * From Win32_Process\") \nFor Each objProcess In colProcess\n If InStr (objProcess.CommandLine, WScript.ScriptName) <> 0 Then\n argStr = Mid(objProcess.CommandLine, InStr(objProcess.CommandLine , WScript.ScriptName) + Len(WScript.ScriptName) + 1)\n End If\nNext\ncmdStr = Trim(argStr)\n\nCreateObject(\"Wscript.Shell\").Run cmdStr, 0, True\n\n<\/pre>\n<p> <\/p>"}}