我如何知道 C# 应用程序是否已从桌面或 cmd shell 启动?
msdn 文档在这部分有点模糊。也许有人可以在这里帮助我 :)
非常感谢!
最佳答案
这似乎可行:
string[] args = System.Environment.GetCommandLineArgs();
if(args[0] == "you exe name"){ ...}
如果双击它,args[0] 包含完整文件夹。
请注意,您需要实际调用 .GetCommandLineArgs()
,即典型 static void Main(string[] 中的
删除了此项。args[]
参数args)
-- 编辑
这只会检测它是否从与 .exe
本身相同的路径运行。如果您从子文件夹 (foo\hello.exe
) 运行它,它将无法运行。
关于c# - 如何确定 C# 应用程序是从桌面还是从 cmd shell 启动的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1392093/