Problem about the constant "$PROFILE"
I remember a problem I met before just now. It is the value of $PROFILE. In fact:
SetShellVarContext all
MessageBox MB_OK "$PROFILE"
SetShellVarContext current
MessageBox MB_OK "$PROFILE"
Get the same value. I suggest using GetAllUsersProfileDirectory function instead:
http://msdn.microsoft.com/en-us/library/bb762276.aspx