Is it possible to use Task Scheduler to open a VBS file without a command window?

12,801

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

Share:
12,801

Related videos on Youtube

Matthew Wai
Author by

Matthew Wai

Updated on September 18, 2022

Comments

  • Matthew Wai
    Matthew Wai over 1 year
    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

    • sgmoore
      sgmoore over 7 years
      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.
    • Matthew Wai
      Matthew Wai over 7 years
      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.
    • sgmoore
      sgmoore over 7 years
      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.
    • Matthew Wai
      Matthew Wai over 7 years
      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?
  • Ben N
    Ben N over 7 years
    Note that the Hidden checkbox applies to whether the task shows up in the Task Scheduler window when View | Show Hidden Tasks is off.
  • Matthew Wai
    Matthew Wai over 7 years
    Actually I have to run a .vbs file rather than a .txt file. I have edited my question. See it again.
  • Matthew Wai
    Matthew Wai over 7 years
    @ Run5k, I had done as you said, but the file could not be run. I have edited my question. Please see it again.
  • Run5k
    Run5k over 7 years
    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?
  • Matthew Wai
    Matthew Wai over 7 years
    Sorry for the misunderstanding. I have edited my question. Please read it again.
  • Matthew Wai
    Matthew Wai over 7 years
    Bingo! That’s what I want. It works perfectly. No command window appears. Thank you very much, w32sh!
  • Ben N
    Ben N over 7 years
    @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.
  • Matthew Wai
    Matthew Wai over 7 years
    Just out of interest, what is the difference between wscript.exe and cscript.exe?
  • Ben N
    Ben N over 7 years
    @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.)