3

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.

  • 1
    Its entirely possible to run VBScript files on Windows 8 out of the box. Your file extension associations seem to be incorrect. sevenforums.com/tutorials/… I am unable to recreate this problem so its your file association that is the problem. – Ramhound Feb 1 '14 at 20:02
  • I agree with Ramhound, unless you are trying to do something special like open a VBScript file with a custom launcher or something. If you simply want to execute just an ordinary .vbs file with the built-in/default WScript interpreter, then your file associations for vbs are hosed and you need to fix them. – allquixotic Feb 1 '14 at 20:04
  • @Ramhound Downloading and applying the VBS reg doesn't seem to fix it. If I associate .foo files with my VBS script, and then try to open a .foo file, Windows 8 still says the same error message. – Jisang Yoo Feb 1 '14 at 20:21
  • I was able to use "open with" on a .vbs file with wordpad and notepad. I was able to double click the file and it ran. Its not clear what you mean by opening a .foo file WITH your VBS file. .vbs IS a file type. Why are you trying to associate .foo to be a VBS file? – Ramhound Feb 1 '14 at 20:25
  • What I want to achieve in the end is to associate .txt and .foo files with GNU Emacs in some special way. This requires associating the files with emacsclientw.exe in a way that some command line options are always passed to emacsclientw.exe. One way to achieve this is to create a batch file containing a line like path\to\emacsclientw.exe --some-options %* and then associate foo files with the batch script. But now a little problem is that the batch file will launch a cmd window (which disappears within a second, so not a big problem). .. – Jisang Yoo Feb 1 '14 at 22:00
1

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

  • 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", ... – Jisang Yoo Feb 2 '14 at 11:10
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!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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