I just don't understand why you are trying to change the environment variables so many times. It should be a rare event. If you need to shell out to run a command that needs some particular environment variable set, then create a batch file that sets those variables and calls your command and then just shell out to the batch file from kix.

Am I missing something? I really didn't follow what you were trying to do, nor why it was necessary. Sorry.