5

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
  • 447
  • 1
  • 5
  • 13
  • 1
    Its entirely possible to run VBScript files on Windows 8 out of the box. Your file extension associations seem to be incorrect. http://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html I am unable to recreate this problem so its your file association that is the problem. – Ramhound Feb 01 '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 01 '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 01 '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 01 '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 01 '14 at 22:00
  • .. I rewrite the batch file as a VBscript in the hope that it may eliminate this little problem while doing the same job as the original batch file. – Jisang Yoo Feb 01 '14 at 22:00
  • (forgot to add the @Ramhound to my previous two comments.) – Jisang Yoo Feb 01 '14 at 22:10
  • Update your question with that information. – Ramhound Feb 02 '14 at 16:35
  • His question already said he wanted to open a vbs file in wordpad, obviously that means he wants the contents of the vbs file to appear in wordpad. (or whatever text editor). That is quite an understandable question. Personally I just have notepad open and drag them into the notepad window(though I recall dragging to a wordpad window didn't work and notepad doesn't support \n new lines.).. I can't experiment now. But as to the batch window opening(you could minimize it but better), try HSTART http://www.ntwind.com/software/hstart.html If I recall it's like HSTART wordpad a.txt – barlop Feb 03 '14 at 11:09
  • Also, you write of the idea of "if something is true, open the text file with wordpad, otherwise open it with notepad," i'd note that to get it to associate with the vbs interpreter you'd associate it with wscript or ccscript. You could do something like wscript somedecision.vbs %1 There is a program that can flexibly do file associations.. http://defaultprogramseditor.com/ – barlop Feb 03 '14 at 16:03

2 Answers2

3

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!

Julius
  • 31
  • 2
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

GrossT
  • 1,079
  • 1
  • 6
  • 11
  • 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 02 '14 at 11:10