Используй вызов
ExpandEnvironmentStrings( LPCTSTR lpSrc, LPTSTR lpDst, DWORD nSize );
Сеpгей Кисуpин (Sergey Kisurin)