/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). &nbsp;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. &nbsp;For example:<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-family: 'courier new', courier;\">&gt; 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;\">&gt; 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:&nbsp;<br \/><span style=\"font-family: 'courier new', courier;\">C:\\hide.vbs \"C:\\Windows\\System32\\makecab.exe\"&nbsp;\"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 &lt; 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) &lt;&gt; 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>&nbsp;<\/p>"}}
comments powered by Disqus
 

Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

 
This page is best viewed with Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+, IE 9+
Copyright © 2014 8bitrobot.com