如何在没有扩展名的情况下运行脚本? [英] how can I run a script without an extension?
问题描述
假设我的桌面上有一个文件,它没有扩展名,但包含一些代码(比如 Batch 或 VBS).
我可以在不向文件添加扩展名的情况下运行此代码吗?
我个人曾考虑使用 powershell 将扩展名传递给 wscript.exe,但结果证明这有点不可能.
Say I have a file on my desktop that doesn't have extension, but contains some code (say Batch or VBS).
Can I run this code without adding an extension to the file?
I was personally thinking about using powershell to pass an extension to wscript.exe, but this turned out to be somewhat impossible.
推荐答案
对于 VBS\JS 脚本,您需要使用 //E
开关指定引擎.
For VBS\JS scripts you need to specify engine with //E
switch.
示例:
- 如果文件
xxx
包含VbScript代码:wscript//E:VBScript c:\xxx
- 如果文件
xxx
包含 JavaScript 代码:wscript//E:JScript c:\xxx
- If file
xxx
contains VbScript code:wscript //E:VBScript c:\xxx
- If file
xxx
contains JavaScript code:wscript //E:JScript c:\xxx
对于批处理文件,没那么容易.有一些解决方法,但它们有些有限:如何在不使用 *.bat 扩展名的情况下运行批处理脚本
For batch files, it's not so easy. There is some workarounds, but they're somewhat limited: How to run batch script with out using *.bat extension
这篇关于如何在没有扩展名的情况下运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!