How do I associate a file type with a VBScript

7,487

Solution 1

I also have a problem that requires a file type to be opened through explorer with a script (vbscript) and have found a solution, you just need to edit the registry.

  1. Go to the following registry key for your filetype: HKCR\YourfileType\Shell\Open\Command
  2. Edit the (Default) key and enter in something like this string

    C:\Windows\System32\cscript.exe "C:\PathToyourScript\Script.vbs" "%1"

The %1 passes the filename to script as a parameter

This is working well for my needs but you may need to test it. Best of Luck!

Solution 2

Instead of using your VBscript file, try using Nirsoft FileTypesMan to modify the command line arguments the .txt and .foo files use when launching emacs.exe

This question is similar to Adding default command line options when opening a particular filetype

Share:
7,487

Related videos on Youtube

Jisang Yoo
Author by

Jisang Yoo

Updated on September 18, 2022

Comments

  • Jisang Yoo
    Jisang Yoo over 1 year

    This question is a natural follow up to How to run a batch file without launching a "command window"?

    One can associate for example .txt files with Wordpad by opening the Properties dialog of a txt file and pressing the Change button next to "Opens with..." and choosing Wordpad. If I do the same with a VBScript file (rather than Wordpad), that is, if I associate .txt files with the VBscript and try to open the associated file (the txt file), Windows shows a pop up saying

    This app can't run on your PC ...
    

    The full quote and the screenshot is exactly the same as one in this thread

    I suspect this error message may be due to some kind of security feature of Windows 8 to prevent users from being tricked into running bad scripts, but the vbs script is created by myself on the same machine, and I wonder if there is a way say "I wrote this. You can trust this script." to Windows. The script runs fine if I run it directly (by double clicking or tapping on it), or if I drag and drop a txt file to the script.

  • Jisang Yoo
    Jisang Yoo over 10 years
    This does solve my X problem. On the other hand, I would not mark this as a duplicate, since a solution to the Y problem would be useful to others: someone might want to pass command line arguments that change at run time or want to use a VBscript that involves conditional logic like "if something is true, open the text file with wordpad, otherwise open it with notepad, and snap the window to left if blah blah.". Solution to Y would also make it easy to create multiple "open with emacs with option 1", "open with emacs with option 2", ...