How to start a batch file minimized with task scheduler in Windows 8? - %comspec% method not working anymore after Windows 7

前端 未结 6 1533
再見小時候
再見小時候 2021-02-01 14:45

After Windows XP, I always use the trick below to start batch files minimized with Windows Task Manager.

From http://www.pcreview.co.uk/forums/running-bat-files-minimize

相关标签:
6条回答
  • 2021-02-01 15:20

    Maybe it's not the same as you mean but if I simply run a .bat file with the scheduler and tick this "Hidden" box on the General tab of the task properties it starts minified.

    0 讨论(0)
  • 2021-02-01 15:27

    Assuming Windows 8 is the same as Windows 7, an "exit" is only going to exit the batch file (which it is going to do anyway).

    You need to add the exit code like this:

    Under "Program/Script":

    CMD (or command.exe, or %comspec%)

    Under "Arguments:

    /c start "Title" /min "C:\Scripts\Destination_inbound_ftp5.bat" ^& exit
    
    0 讨论(0)
  • 2021-02-01 15:29

    Another possibility: a small freeware program named CMDH, that simply runs the requested orders in background. For example:

    cmdh MyScript.cmd
    

    No need to add "exit" to the script. Tested working in Windows XP SP3, and there is no reason it should fail on Windows 8.

    0 讨论(0)
  • 2021-02-01 15:35

    I didn't like seeing the command window pop up and then disappear so here is another solution from https://ss64.com/vb/run.html ...

    First create invisible.vbs with this single line of text:

    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
    

    Next and finally, launch your cmd or batch file via:

    %SystemRoot%\system32\wscript.exe "invisible.vbs" "myscript.cmd" //nologo
    

    Ta da! Scripting of this sort has been built into Windows for a long time. If you're curious, do a web search for "WSH" (windows scripting host). You can even write such scripts in dialect of JavaScript called JScript.

    0 讨论(0)
  • 2021-02-01 15:40

    The start command needs the leading "" quotes to disable the title feature. Try scheduling this:

    %comspec% /c start "" /min "C:\Scripts\Destination_inbound_ftp5.bat"
    
    0 讨论(0)
  • 2021-02-01 15:41

    Here's a solution from https://ss64.com/vb/run.html that will run a batch file in a minimized window. Unlike the other solutions that use the start command with /min, this one will not flash a new window onto your screen or interrupt full-screen activities. It does, however, steal focus. I don't know how to avoid that.

    First create a file named run_minimized.vbs with this single line of text:

    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 2, False
    

    Next, create your Task Scheduler task with an action to start the program wscript.exe with these arguments:

    "c:\path\run_minimized.vbs" "c:\path\my script.bat"
    

    Change the paths as necessary to specify the locations of the two files.

    There is no simple way to pass arguments from Task Scheduler to the batch file while also preserving spaces and quotation marks, because wscript strips quotation marks from its arguments. The simplest way to handle arguments with spaces would be to put the entire batch file command into the vbs:

    CreateObject("Wscript.Shell").Run  """c:\path\my script.bat"" ""arg 1"" arg2", 2, False
    

    Note the use of quotation marks. There's one pair of quotation marks " enclosing the entire command string, and a pair of adjacent quote characters "" every place you'd use a normal quotation mark in a command line.

    0 讨论(0)
提交回复
热议问题