choco icon indicating copy to clipboard operation
choco copied to clipboard

Make refreshenv.bat error if powershell.exe is being used

Open ferventcoder opened this issue 8 years ago • 9 comments
trafficstars

If someone has the powershell profile installed, they would never call this as refreshenv is an alias for Update-SessionEnvironment.

This is quite difficult to determine. I found https://stackoverflow.com/a/16376399/18475, but it won't work if you drop from PowerShell.exe to cmd.exe to run commands, and I haven't found a way to capture the current title and set it back yet.

It also doesn't determine the difference between cmd started up just to run a batch and a long term child process of cmd.exe that you get if you open PowerShell and then drop into cmd.exe (call cmd.exe in PowerShell opens a child process). The script found can not tell the difference between the two.

ferventcoder avatar Aug 27 '17 14:08 ferventcoder

I think I've solved this problem: beatcracker/choco@9e0d484 . Unfortunately I don't feel like signing CLA. Could you use my solution if I to release it separetely with some very permissive license (WTFPL or something like that)?

beatcracker avatar Oct 23 '17 11:10 beatcracker

@beatcracker how will this work if say I'm in powershell.exe and then call cmd.exe to go into that prompt before calling refreshenv?

ferventcoder avatar Oct 23 '17 12:10 ferventcoder

Looks like it could work. Don't feel like signing the CLA or are unable to?

ferventcoder avatar Oct 23 '17 12:10 ferventcoder

how will this work if say I'm in powershell.exe and then call cmd.exe to go into that prompt before calling refreshenv?

It will refresh env. vars inside that cmd session. But if you run it as RefreshEnv.cmd from PS console it will show the warning. I've tested this in both PS console and ISE.

Don't feel like signing the CLA or are unable to?

Don't feel like. It requires sharing my personal data and this is something I'm very reluctant to do. Sorry about that.

beatcracker avatar Oct 23 '17 13:10 beatcracker

It requires sharing my personal data and this is something I'm very reluctant to do.

Understood. It probably won't help, but the data goes nowhere. We don't share it with anyone.

Set up something generic in a repository and give it a very permissive license. Then we can take a closer look.

ferventcoder avatar Oct 23 '17 14:10 ferventcoder

Set up something generic in a repository and give it a very permissive license. Then we can take a closer look.

Sure, will MIT be suitable?

beatcracker avatar Oct 23 '17 15:10 beatcracker

MIT is perfect.

ferventcoder avatar Oct 23 '17 15:10 ferventcoder

Done: https://github.com/beatcracker/detect-batch-subshell

beatcracker avatar Oct 23 '17 16:10 beatcracker

So I took the sample code from @beatcracker for a spin (as well as previously having done some investigating on this myself). I had hoped to use a separate file that could be fully attributed to beatcracker, but it appears that's not possible (if you call the cmd from within a cmd, it detects as being run interactively 😅 ).

I have a bit of work to do to get it ready for a PR, but should have a PR up for this by the end of the month 😄

corbob avatar Apr 22 '22 22:04 corbob

@vexx32 can you update this issue with the milestone is this work intended to go out on?

gep13 avatar Oct 02 '22 07:10 gep13