11

I am trying to run a .vbs file on every five minutes.

I am trying to do this using windows task scheduler.

In Actions tab -> New Action, I select the file ("D:\Documents\FC3 Savegames\FC3.vbs") using open file dialog

I have made all other setting properly.

But whenever the task begin, It opens open with dialog every time.

Once I choose Notepad to in open with dialog. Then Another dialog opens from Notepad saying Can not find D:\Documents\FC3.txt file. Do you want to create a new file with three buttons Yes, No and Cancel

Help me what is wrong.
I feel that white spaces in the file path causing the problem.

Added later
Well I just fixed this by setting path to shorthand ("D:\Documents\FC3Sav~1\FC3.vbs"). But it still opens "open with" dialog everytime. Now it has two main programs saying "Keep using Microsoft Windows Script Host" and Other Program. This dialog does not open when I run vbs file directly.

8
  • Does the script run if you just type "D:\Documents\FC3 Savegames\FC3.vbs" on the command line? If not, it sounds like the .vbs extension isn't associated with the VB interpreter. You might be able to use CScript.exe to run it if that's the case.
    – martineau
    Feb 24, 2013 at 16:49
  • @martineau yes it works. Well I just fixed this by setting path to shorthand ("D:\Documents\FC3Sav~1\FC3.vbs"). But it still opens "open with" dialog everytime. Now it has two main programs saying "Keep using Microsoft Windows Script Host" and Other Program. This dialog does not open when I run vbs file directly.
    – shashwat
    Feb 24, 2013 at 16:52
  • @martineau and If I choose first option "Microsoft Windows Script Host", it runs. But it asks every time when task begins to execute.
    – shashwat
    Feb 24, 2013 at 16:54
  • Run Wscript.exe then select "Always use this program to open this file type". This registers Wscript.exe as the default script host for files of this file type.
    – martineau
    Feb 24, 2013 at 16:55
  • running this command does not come up with any such options. Look on the s3.postimage.org/jncacec6r/temp.png
    – shashwat
    Feb 24, 2013 at 16:59

4 Answers 4

4

Here's what it says about Wscript.exe in the Help file I have:

To run scripts using the Windows-based script host (Wscript.exe) You can run scripts with the Windows-based script host in the following ways:

  • By browsing in Windows

    Browse to the folder containing the script you want to run and double-click it. Script files can be listed in My Computer, Windows Explorer, the Find window, the Start menu, or on your desktop.

  • By using the Run command

    Click Start, and then click Run. In Open, type the name of the Windows Host executable file (Wscript.exe), followed by a space, then the full path name of the script you want to run. Be sure to include the file name extension of the script file. Click OK to start the script.

  • From a command prompt window

    At the command prompt, type the name of the Windows Host executable file (Wscript.exe), followed by a space, then the full path name of the script you want to run. Be sure to include the file name extension of the script file. Press Enter to start the script.

Notes

  • Windows scripts are files with the following file name extensions: .wsf, .vbs, .js.
  • If you double-click a script file whose extension has not been associated with Wscript.exe, the Open With dialog box appears. Select Wscript.exe, then select Always use this program to open this file type. This registers Wscript.exe as the default script host for files of this file type.
  • You can use the Windows Script Host Settings dialog box to set global scripting properties for all scripts that Wscript.exe runs on the local computer.
  • You can set properties for individual scripts. See Related Topics for information about how to do this.
  • You can also use Windows Script Host to create .wsf script files, with which you can call multiple scripting engines and perform multiple jobs, all from one file.

Here's what it says about Cscript.exe:

Using the command-based script host (CScript.exe)

Cscript.exe is a command-line version of the Windows Script Host that provides command-line options for setting script properties.

With Cscript.exe, you can run scripts by typing the name of a script file at the command prompt. Like Microsoft Internet Explorer, Windows Script Host serves as a controller of Windows Script compliant scripting engines, but Windows Script Host has very low memory requirements. Windows Script Host is ideal for both interactive and non-interactive scripting needs, such as logon scripting and administrative scripting.

Windows Script Host supports scripts written in VBScript or JScript. When you start a script from your desktop or from the command prompt, the script host reads and passes the specified script file contents to the registered script engine. The script engine uses file extensions (that is, .vbs for VBScript and .js for JScript) to identify the script. As a result, you do not need to know the exact programmatic identifier (that is, the ProgID) of the script engine. The script host maintains a mapping of script extensions to programmatic identifiers, and uses the Windows XP association model to start the appropriate engine for a given script.

Update:

Here's a registry file called "FixVBSFileAssociationsXP.reg" which will fix up the file assocations for you on XP. A different one would be needed for Win 7.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.reg]
@="regfile"

[HKEY_CLASSES_ROOT\.reg\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\regfile]
@="Registration Entries"
"EditFlags"=dword:00100000

[HKEY_CLASSES_ROOT\regfile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,72,00,65,00,67,00,65,00,64,00,69,00,74,00,2e,00,65,00,78,00,65,00,\
  2c,00,31,00,00,00

[HKEY_CLASSES_ROOT\regfile\shell]

[HKEY_CLASSES_ROOT\regfile\shell\edit]

[HKEY_CLASSES_ROOT\regfile\shell\edit\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

[HKEY_CLASSES_ROOT\regfile\shell\open]
@="Mer&ge"

[HKEY_CLASSES_ROOT\regfile\shell\open\command]
@="regedit.exe \"%1\""

[HKEY_CLASSES_ROOT\regfile\shell\print]

[HKEY_CLASSES_ROOT\regfile\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\
  00,25,00,31,00,00,00

Here's a version called FixVBSFileAssociationsVista.reg for Vista and Window 7, which might work on Windows 8, too, but use at your own risk (back up your registry first, if possible):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.VBS]
@="VBSFile"

[HKEY_CLASSES_ROOT\.VBS\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\VBScript]
@="VB Script Language"

[HKEY_CLASSES_ROOT\VBScript\CLSID]
@="{B54F3741-5B07-11cf-A4B0-00AA004A55E8}"

[HKEY_CLASSES_ROOT\VBScript\OLEScript]

[HKEY_CLASSES_ROOT\VBSFile]
"FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
  32,00,5c,00,77,00,73,00,68,00,65,00,78,00,74,00,2e,00,64,00,6c,00,6c,00,2c,\
  00,2d,00,34,00,38,00,30,00,32,00,00,00
@="VBScript Script File"

[HKEY_CLASSES_ROOT\VBSFile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,53,00,\
  63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,2c,00,32,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\ScriptEngine]
@="VBScript"

[HKEY_CLASSES_ROOT\VBSFile\ScriptHostEncode]
@="{85131631-480C-11D2-B1F9-00C04F86C324}"

[HKEY_CLASSES_ROOT\VBSFile\Shell]
@="Open"

[HKEY_CLASSES_ROOT\VBSFile\Shell\Edit]

[HKEY_CLASSES_ROOT\VBSFile\Shell\Edit\Command]
@=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,\
  6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,22,00,20,00,25,\
  00,31,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open]

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command]
@=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,\
  53,00,63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,22,00,20,00,22,\
  00,25,00,31,00,22,00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open2]
@=hex(2):4f,00,70,00,65,00,6e,00,20,00,26,00,77,00,69,00,74,00,68,00,20,00,43,\
  00,6f,00,6d,00,6d,00,61,00,6e,00,64,00,20,00,50,00,72,00,6f,00,6d,00,70,00,\
  74,00,00,00
"MUIVerb"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
  6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,\
  00,77,00,73,00,68,00,65,00,78,00,74,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,\
  34,00,35,00,31,00,31,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open2\Command]
@=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,43,00,\
  53,00,63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,22,00,20,00,22,\
  00,25,00,31,00,22,00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Print]

[HKEY_CLASSES_ROOT\VBSFile\Shell\Print\Command]
@=hex(2):22,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,\
  6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,22,00,20,00,2f,\
  00,70,00,20,00,25,00,31,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\ShellEx]

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\PropertySheetHandlers\WSHProps]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"
6
  • 1
    yes it worked. I use wscript.exe in start program and pass file path in shorthand (may full path will work here with double quotes). Can u tell me why it opens command prompt (just blink once) when using cscript.exe instead. What is different in both..?
    – shashwat
    Feb 24, 2013 at 17:20
  • I suppose because "With Cscript.exe, you can run scripts by typing the name of a script file at the command prompt" -- in other words because it's a command-line program (and Wscript.exe is not).
    – martineau
    Feb 24, 2013 at 18:24
  • I am on windows 8
    – shashwat
    Feb 24, 2013 at 20:39
  • Should have mentioned that in your question...
    – martineau
    Feb 24, 2013 at 23:21
  • do you have a link to the webpage you used to aid in the construction of those .reg files? or info on how you did it, whether it was a reg file you got from elsewhere and amended? or even what it does. it says fix, but i wasn't aware they were broken
    – barlop
    Oct 20, 2013 at 15:09
9

Old question, but I ran across it too and it helped me solve my problem, so I figured I'd share what worked for me. Setting the command to C:\Windows\System32\wscript.exe and passing the path to my script as an argument made it work like a charm, with no other modifications needed. Here's a screenshot for reference:

Settings for scheduled scripts:

enter image description here

1
  • Using SCHTASKS.exe to schedule such file to run every 5 minutes looks like this: SCHTASKS.EXE /create /tn MyTask /sc minute /mo 5 /tr "'C:\Windows\System32\wscript.exe' 'C\Users\Billy\MyScript.vbs'". The quotes after the TR can cause headaches. Open and close with double both exe and script full path. Enclose both paths in single quotes (so you can have spaces).
    – kolcinx
    Aug 13, 2017 at 12:37
3

I just had the same problem. It turned out that Windows 8 does not tolerate spaces and quotation marks in file names. In the "Program/scripts field", instead of

"D:\Documents\FC3Sav~1\FC3.vbs"

you should use

D:\Documents\FC3Sav~1\FC3.vbs

So, if you remove both spaces and quotation marks from the "Program/script" field, your scheduled script will run normally without popping up the "Open with" dialog.

1
  • I had this problem when running a Python script, and it didn't occur to me that the quotes were the problem. Thank you.
    – Eryk Sun
    May 3, 2017 at 13:35
2

As program select cscript.exe and as parameter point to the VBS file.

2
  • 1
    It worked but again this way disappoints me. It opens cmd prompt window for a little while (just a blink). It interrupts my programs. Why .vbs file can not be run from scheduler directly without opening "open with" dialog..?
    – shashwat
    Feb 24, 2013 at 17:12
  • @shashwat, use wscript.exe instead of cscript.exe
    – Adir Dayan
    Feb 21, 2022 at 18:59

You must log in to answer this question.

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