Implement support for environment variables on Windows.

Fixes #6049