win: roll a custom environment variable sorter, and drop invalid environment variables

also, wcscpy_s is not available in XP