如何区分 VBscript 是从命令行运行还是在窗口中单击它? [英] How to tell the difference between a VBscript is run from command line or by clicking it in a window?

查看:21
本文介绍了如何区分 VBscript 是从命令行运行还是在窗口中单击它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是区分由命令行运行的程序或通过单击窗口中的 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: estFolder est.vbs 来运行脚本,那么我希望程序的运行方式与双击 test.vbs<时不同/code> 在 testFolder 中.

If you run the script by typing C: estFolder est.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.

非常感谢任何想法.

推荐答案

你可以试试这样的:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆