Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
747 views
in Technique[技术] by (71.8m points)

scripting - How to tell the difference between a VBscript is run from command line or by clicking it in a window?

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.

If you run the script by typing C:estFolderest.vbs in a command prompt, then I want the program to run differently than if you double clicked test.vbs in the testFolder.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try something like this:

Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")

msgbox objenv("PROMPT")

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...