2
set objShell = createobject("wscript.shell")  
objShell.Run("""C:\Program Files\Windows Defender\MpCmdRun.exe"" ""-SignatureUpdate""") , 0 <br>

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "D:\Balloontip.vbs" & Chr(34), 0
Set WshShell = Nothing

The above is used in a VBS file. When I use Task Scheduler to run it, a command window will appear and then disappear immediately. Is it possible to run it without any command window?

If I use the 'Matthew_Wai' user account, the .vbs file can be run with a momentary window.
But if I use 'SYSTEM' as shown below, the .vbs file cannot be run with no window and error message (nothing happens at all).
(I can change my display language to English if need be.) enter image description here

  • 1
    Why can't you run the vbs script? (Did you try running cscript.exe with your vbs script as an argument?) Also, if you are just wanting to open the txt file in notepad, you can run notepad directly and pass the txt file as the argument. – sgmoore Nov 26 '16 at 11:06
  • Task Scheduler cannot directly run a VBS file. Can you teach me how to use Task Scheduler to run cscript.exe with my vbs script as an argument? Actually, the vbs script is used to run a bat file rather than a txt file. – Matthew Wai Nov 26 '16 at 12:11
  • 1
    When you create a task to start a program, it should ask for the program which is in your system32 folder, (ie normally c:\windows\system32\cscript.exe) and it you ask for arguments and you need to enter the full path name of your script file. – sgmoore Nov 26 '16 at 13:20
  • Thanks, it works. But when it runs, a command window will still appear and then disappear immediately. Is it inevitable when Task Scheduler runs a file? – Matthew Wai Nov 26 '16 at 13:27
2

Use wscript.exe to run the script, instead of cscript.exe

| improve this answer | |
  • Bingo! That’s what I want. It works perfectly. No command window appears. Thank you very much, w32sh! – Matthew Wai Nov 27 '16 at 16:05
0

I typically configure the tasks that I create within Task Scheduler to utilize the built-in System account and also check the box to mark them as Hidden. As a result, I never see any interface appear on the screen:

Task Scheduler

| improve this answer | |
  • Note that the Hidden checkbox applies to whether the task shows up in the Task Scheduler window when View | Show Hidden Tasks is off. – Ben N Nov 26 '16 at 20:29
  • @ Run5k, I had done as you said, but the file could not be run. I have edited my question. Please see it again. – Matthew Wai Nov 27 '16 at 6:53
  • Before you said that it was running, but a window would briefly appear... but now it isn't running at all? If the file couldn't be run, what type of error (if any) are you seeing? – Run5k Nov 27 '16 at 9:02
  • Sorry for the misunderstanding. I have edited my question. Please read it again. – Matthew Wai Nov 27 '16 at 12:01
0

The Task Scheduler will happily open a file with the default handler if the task runs only when the user is logged on, i.e. with access to the desktop. (Otherwise the handler will run, but the window it creates will be in session 0 with all the invisible system stuff.)

Therefore, a configuration like this does exactly what you want:

execute the file itself

One downside: Task Scheduler doesn't like spaces in the path, even if you quote it, so if your file's full location has a space, you might have to use the abbreviated 8.3 name for one or more path components.

| improve this answer | |
  • Actually I have to run a .vbs file rather than a .txt file. I have edited my question. See it again. – Matthew Wai Nov 27 '16 at 6:43
  • @MatthewWai For what it's worth, running a VBS script also works for me as long as the default handler for that file type is wscript. I'm glad the other answer works for you. – Ben N Nov 27 '16 at 18:10
  • Just out of interest, what is the difference between wscript.exe and cscript.exe? – Matthew Wai Nov 28 '16 at 3:52
  • @MatthewWai cscript is designed to run scripts in a console, while wscript is marked as being an application that can create windows. (Relevant SO question.) – Ben N Nov 28 '16 at 15:28
0

You can use the Hidden Start utility to run a script without the console window appearing by using the /NOCONSOLE switch.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.