Add context manager for WMI calls

Fixes #3266
Fixes #3105
Fixes #3349

Import file functions for non-platform dependent actions