I have a scheduled task that starts a batch script that runs robocopy
every hour. Every time it runs a window pops up on the desktop with robocopy's output, which I don't really want to see.
I managed to make the window appear minimized by making the scheduled job run
cmd /c start /min mybat.bat
but that gives me a new command window every hour. I was surprised by this, given cmd /c
"Carries out the command specified by string and then terminates" - I must have misunderstood the docs.
Is there a way to run a batch script without it popping up a cmd window?
You could run it silently using a Windows Script file instead. The Run Method allows you running a script in invisible mode. Create a
.vbs
file like this oneand schedule it. The second argument in this example sets the window style. 0 means "hide the window."
Complete syntax of the Run method:
Arguments:
Are you running this as a scheduled task? If so set it to run as a different user account then it won't be visible to the logged on user. If the script needs no network access to items that need windows auth (like file shares or printers), you can run it as "nt authority\system" and leave the password blank. On Windows 7, just set the user to SYSTEM, and press OK.
(You probably have to use a real user though if you're using robocopy...)
JR
Simply configure the Scheduled Task as "Run whether user is logged on or not".
You could also try CHP (Create hidden process), does exactly what you'd think...
Runs with no command window. Perfect! Made by the same people as CMDOW, but this is more appropriate.
CMDOW is an awsome tool that allows you to do many, many things to windows from the command line.
One of the simplest things to do is hide the current window (usually as a first line in the bat file) with:
or start a new hidden process with
You can create a shortcut to the batch file, set the shortcut to start minimized (in the shortcut's properties, 'Shortcut' tab), and then set the job to start the shortcut.
Important: You'll need to specify the path to the shortcut manually by typing it into the Run text field, complete with the '.lnk' extension; if you just try to browse to it, it will helpfully redirect itself to whatever the shortcut points to.
Try invoking the script with
I realize this question has already been answered with a perfectly good resolution that is native to Windows and thus should be the most compatible, and I agree completely.
I also wanted to say that I disagree with @splattne's comment (but not his actual answer) -- that the resolution in the other referenced thread deserves the credit. That answer involves running the script as a different user (SYSTEM), which is pretty much the equivalent of giving the script root access. It will also fail for jobs such as
ROBOCOPY
(as referenced by John Rennie), which require network access.I have never tried
CMDOW
before, but I would like to offer another similar resolution, which [although is not natively-installed on Windows] is still highly-portable to most versions, and comes in both 32 and 64-bit versions, and that is NirCmd.NirCmd is a very powerful tool that has myriads of options, the most useful of which, I personally find to be its ability to launch hidden command windows by simply executing the following:
From the
exec
section of The NirCmd Command Reference:Runs an application, and optionally specify one or more command-line parameters for the executed application. The [show/hide/min/max] parameter specifies whether the running application will be visible or not. If 'hide' is specified, the running application won't be visible to the user. If 'max' is specified, the running application window will be maximized. If 'min' is specified, the running application window will be minimized.
EDIT: I was trying to run a
ROBOCOPY
job and tried the method in this answer, and it did not work, even after editing the network access privileges. I tried double-clicking the script and could not get it to work, but could only get it to run under an elevated command prompt. I did create a shortcut to the batch file and have it run as Administrator and was able to get it execute by double-clicking it, but the method I ended up going with was to run it hidden as SYSTEM (I know, I know) -- but it does work withROBOCOPY
, for what it's worth, as long as the batch file has the correct permissions.EDIT 2: For some reason, it would not work as SYSTEM (probably the network access thing referenced earlier) -- I only noticed this after actually running
ROBOCOPY
without the /L flag, which is basically just a simulation and [apparently] doesn't actually connect to the remote system, but when I run the batch file with highest privileges and check the hidden box, and I can still run it as the logged in user in the background without a command window showing, for whatever this is worth to anyone.Another solution I've used is Hidden Start
Try putting in an exit command at the end of your batch file. This should close the command window when the script is done.