powershell - Find out if process is running in a cmd.exe or PoweShell window -


imagine you're writing program in high level language not allowed custom system calls (win32 api) because code cross compiling or language doesn't support that.

when process running on windows, there way find out if you're running inside powershell , not cmd.exe? or vice versa?

i'm trying print "i'm running in powershell" , "i'm running in cmd.exe" program.

in case i'm writing program in golang shouldn't matter because don't want traverse process tree.

eryksun might have point usefullness of there post getting parent process.

putting following text ps1 script:

$parentpid=(gwmi win32_process -filter "processid='$pid'").parentprocessid write-host ("i running in {0}" -f (get-process -id $parentpid).name) 

running cmd calling powershell:

i running in cmd

running powershell , ise:

i running in explorer

so while explorer not useful not cmd think wanted know.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -