Call BAT in a larger window and change the ENV variables to

In a PowerShell script, I have to call the batch file in a larger window. Therefore i do

Start-Process my.bat -Verb runas

Now it my.batexpects some of the ENV variables that I set in the original window to be present. However, since the elevated window runs as admin, these variables, which I set as a regular user, do not appear in the admin window.

Is there any way to set ENV vars in admin window before calling my.bat?

+3
source share
1 answer

, , . . , script, , script my.bat.

IIRC "runas" PowerShell, script :

@echo off

set "VARIABLE1=%1"
set "VARIABLE2=%2"

call "C:\path\to\my.bat"

:

Start-Process .\wrapper.ps1 -ArgumentList 'foo', 'bar' -Verb runas
+2

Source: https://habr.com/ru/post/1016631/


All Articles