2

I've got the following command running as scheduled task in Windows 8

cmd /C copy /Y nul B:\keepalive.txt

However, when it runs it opens the command prompt window for fraction of second, and that's enough to make it annoying.

How can I run the same command but without opening the command prompt windows?

3
  • 1
    Wrap your code in a VBS script and point your task to this file. VBS scripts can run CMD commands in a hidden window. Read this answer to see how it works. Remember: In your case, you can put the CMD command copy /Y nul B:\keepalive.txt directly into that VBS, and no additional CMD file is needed like I explained over there. Currently at work I can't write a full answer, I hope you get the idea.
    – nixda
    Sep 6, 2013 at 9:42
  • @nixda, why is your excellent comment not posted as an answer?
    – Dave
    Sep 6, 2013 at 11:07
  • @nixda, this doesn't work as advertised :) there as two issues I faced trying to make this work. First one, which isn't a big deal, when I used the command copy /Y nul B:\keepalive.txt in the VBS file it returns an error, something like the script can't file the specified file, so I put the entire cmd /C copy /Y nul B:\keepalive.txt command. The second issue, the scheduled task cannot run VBS files and always displays "How do you want to open this file?" dialog. I'm on Windows 8, as previously said, and double-clicking the file works; i.e. the file is executed.
    – TheBlueSky
    Sep 6, 2013 at 11:43

1 Answer 1

2

Wrap your code in a VBS script and point your task to this file

VBscript's run method can execute batch commands in a hidden window, if you set "intWindowStyle" to 0.

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 

Put this code into your HiddenTask.vbs file.

Set wShell = CreateObject ("Wscript.Shell") 
wShell.Run "cmd /c copy /Y nul D:\keepalive.txt", 0

I successfully tested your example. It creates a new empty file just like it should. Of course without displaying any window.


Read this SO question regarding your issue that it's not working when used as scheduled task. Grant your job administrator rights and set the "start in" folder. Also, check the event log for this task.

Additionally I made some screenshots. Maybe you are able to find the difference to your setup.

enter image description here enter image description here enter image description here

IMPORTANT If you're facing an issue after following the instructions here, please read the comments below, the issue may be the file name or path.

4
  • Thanks for the detailed answer. This is what I've already done and my issue is with "How do you want to open this file?" dialog displayed instead of the script running. It isn't a permission issue (I'm running it under my user) and the referenced Stackoverflow question doesn't say a thing about the "How do you want to open this file?"
    – TheBlueSky
    Sep 8, 2013 at 17:49
  • have you tested the "start in" folder setting like mentioned here?.
    – nixda
    Sep 8, 2013 at 17:54
  • sorry for the late reply. Yes, I tried the "Start in" and the result is the task doesn't even "see" the script file, it's as if the "Start in" doesn't have any effect. Just to iterate on that, the task obviously reaches the file, however, it cannot run it as if it was double-clicked.
    – TheBlueSky
    Sep 13, 2013 at 8:19
  • You know what's even more frustrating, all this issue is because the schedule tasks doesn't like spaces in the path as well even if I used quotation mark around it (actually the quotation mark makes the run fail); it also doesn't like anything other than letters and numbers. When I moved my script to a space-less path, it worked. Who's stupid idea was this? Where I put my files and what I call them is none of your business, Microsoft.
    – TheBlueSky
    Sep 13, 2013 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .