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

前端 未结 6 1598
再見小時候
再見小時候 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: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.

提交回复
热议问题