如何分辨VBscript是通过命令行运行还是通过在窗口中单击来运行? [英] How to tell the difference between a VBscript is run from command line or by clicking it in a window?
问题描述
我要做的就是区分是通过命令行运行的程序,还是单击窗口中的test.vbs文件。
All I want to do is differentiate between the program being run by the command line or by clicking the test.vbs file in a window.
如果运行通过在命令提示符下键入 C:\testFolder\test.vbs
脚本,那么我希望程序的运行方式与双击的方式不同
。 testFolder
中的test.vbs
If you run the script by typing C:\testFolder\test.vbs
in a command prompt, then I want the program to run differently than if you double clicked test.vbs
in the testFolder
.
是否有一些系统变量可用于区分这两种情况?我首先尝试使用 WScript.Fullname
确定路径名是以cscript还是wscript结尾。但是,效果不是很好。
Is there some system variable that I can use to differentiate between the two scenarios? I first attempted to use WScript.Fullname
to determine if the pathname ended in cscript or wscript. But that didn't work so well.
任何想法都会受到赞赏。
Any ideas are greatly appreciated.
推荐答案
您可以尝试以下方法:
Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
msgbox objenv("PROMPT")
通常,从命令提示符运行时,PROMPT将设置为类似$ P $ G的内容,但在您可以直接运行.VBS文件。
In general PROMPT will be set to something like $P$G when run from a command prompt, but left blank when you run the .VBS file directly.
这篇关于如何分辨VBscript是通过命令行运行还是通过在窗口中单击来运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!