unyttig.INFO Your source to not so useless information

25Apr/090

How to: Hide a batch cmd window

Have you ever tried to run a Java Swing application by clicking on a batch file in windows? Then you've probably seen the empty command window and the swing application popping up. If you have no interests in monitoring any error messages in the command window, wouldn't you like to hide it somehow? Well, here's how you do it.

First create a AppStart.bat with the following code inside, this file can of course contain any other application starters, such as pTunnel or any other window that just wont go away:

java -jar MyApp.jar

Next you have to create the actual run.bat this is the bat file that takes care of the actual hiding of the application, this is how you do it:

@echo off
setlocal
set VBS=%TEMP%\HideCmdWindow.vbs
if exist %VBS% goto Runit
@echo dim obj, obj1, obj2, objArgument>%VBS%
@echo Set WshShell = WScript.CreateObject("WScript.Shell")>>%VBS%
@echo Set objArgument = Wscript.Arguments>>%VBS%
@echo obj = WshShell.Run("AppStart.bat", 0)>>%VBS%
@echo set WshShell = Nothing>>%VBS%
:Runit
set param=%*
set param="%param:"="`%"
cscript //nologo %VBS% %param%
endlocal

Now you can start you application by simply clicking on run.bat and the command window should now be hidden. Have fun!

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Slashdot
  • StumbleUpon
  • Twitter
  • LinkedIn
  • RSS

Related posts:

  1. Bash: Volume notification script
  2. Python ImageShack uploader script
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.