0

There are a lot of questions already asking similar things but none helped me:

What i'm f.e. after is:

Create a batch- oder powershell script which

  1. installs python to a system where python isn't installed (this works)
  2. after a successful installation, run python with a python script as argument

(It should also work the same way for installing and using other apps like MSVC, git for windows, ...)

After installing python from a console, the path which has been added to the system environment variables isn't reflected in the current cmd instance environment.

But it's there when i start a new cmd or elevated cmd manually from the windows start menu and not from a script.

I tried the following without luck to update the environment of the existing console or create a new instance with the new user environment from script:

  • start /i/b&exit
  • start /i/b "%windir%\explorer.exe" "%windir%\system32\cmd.exe"
  • powershell -Command Start-Process -UseNewEnvironment -Wait -FilePath python -ArgumentList "test.py"

But for UseNewEnvironment it's documented that

the new process starts only containing the default environment variables defined for the Machine scope. This has the side effect that the $env:USERNAME is set to SYSTEM. None of the variables from the User scope are included

and for start /i that

Ignore any changes to the current environment, typically made with SET. Use the original environment passed to cmd.exe

I think both approaches cannot be used for what i'm after.

Is there a simple possibility to automatically run a script in the new environment which the installer created without extensive code or third party binaries?

ridilculous
  • 624
  • 3
  • 16

0 Answers0