Improve compatibility with Windows.

Fixes #5287