Search code examples
windowspathadminrunas

Windows runs as admin resets PATH.


I've been experiencing a frustrating issue with Windows Run as Administrator. I have a program A which needs to be run as administrator. I also have a program B which is used to manage dependencies of other programs (mainly it creates Command Shells with the right environment variables). Now I don't have control over the B program, but for some reason it creates the Command Shell under a non-admin user even if I run it as admin. So when I start program A from the command shell, it fails because it doesn't run as admin. If I use the runas command to run it as admin, or if I set A's properties to always run as admin, when it starts it doesn't start in the environment created by B, so it doesn't get the PATH (and other environment vars). Does someone know if there is a way to use the runas command while preserving the current environment variables?


Solution

  • Have you tried the /env switch?

    c:\>runas /?
    [...]
       /env              to use current environment instead of user's.
    [...]