c# - Determine whether Console Application is run from command line or Powershell -
how determine whether console application being run powershell or standard command line within application?
something might more reliable checking window title:
using system; using system.diagnostics; process p = process.getcurrentprocess(); performancecounter parent = new performancecounter("process", "creating process id", p.processname); int ppid = (int)parent.nextvalue(); if (process.getprocessbyid(ppid).processname == "powershell") { console.writeline("running in powershell"); } else { console.writeline("not running in powershell"); }
[source]
Comments
Post a Comment