terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Powershell as Admin - Ignoring system path variable

Open SteseDav opened this issue 2 years ago • 9 comments

Windows Terminal version

1.15.3466.0

Windows build number

Version 10.0.22000.856

Other Software

No response

Steps to reproduce

Windows Powershell (elevated to admin) reads the PATH system variable and uses the items within correctly. (I have a custom scripts folder which I call all the time, so it's easier to just type the command)

With a Powershell tab in Terminal, running as admin, doesn't seem to do this by default,

Expected Behavior

I should be able to reference my powershell scripts directly without using the full path.

Actual Behavior

Powershell in Terminal cannot find the scripts, and gives a standard "unable to find" error.

SteseDav avatar Jan 16 '23 09:01 SteseDav

What's the environment in each type of session (elevated vs unelevated)? I just wanna see if there's anything immediately obvious about the difference that jumps out.

How are you running the Terminal as admin? Via some mechanism in the OS (like right-clicking on the taskbar, or via the Start Menu), or are you using the Terminal's built-in "run this profile elevated" functionality/?

(note to self: this isn't going to be a defterm thing, cause obviously, defterm doesn't work for an elevated powershell.exe)

zadjii-msft avatar Jan 16 '23 11:01 zadjii-msft

HI,

Sorry, i'm not following specifically what you mean by environment here. I'm on a Windows 11 machine, with local admin rights to the machine. (sorry if I'm being dense).

I'm using Terminals inbuilt 'Run this profile as Administrator' option.

Regards,

Steve D.

SteseDav avatar Jan 16 '23 14:01 SteseDav

Oh sorry, I meant PATH when I said "environment". Whoops, that's on me :facepalm:

zadjii-msft avatar Jan 16 '23 15:01 zadjii-msft

Ahh! I see... I have simply added a folder to the path variable. In the path below, it's highlighted in bold text.

PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;%ONEDRIVE%\Documents\Code_Script;C:\Users\SDavison\AppData\Local\Microsoft\WindowsApps;;C:\Users\SDavison\AppData\Local\Programs\Microsoft VS Code\bin

SteseDav avatar Jan 16 '23 15:01 SteseDav

Sorry, to extra clarify - is that the PATH in an unelevated window, or the PATH in an elevated (admin) window?

What's the PATH look like for the other type of window?

zadjii-msft avatar Jan 19 '23 17:01 zadjii-msft

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Jan 23 '23 19:01 ghost

That's the system environment PATH, its from neither window.

SteseDav avatar Jan 24 '23 08:01 SteseDav

Gotcha - so, what does PATH look like in each of an elevated/unelevated window/? Maybe there's some diff in one of those PATHs (when compared to what it should be) that might give us a clue as to where the issue is originating.

This might get better in 1.17 after #14637, so I might also have you try out that build (when we release it later today)

zadjii-msft avatar Jan 24 '23 12:01 zadjii-msft

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Jan 28 '23 13:01 ghost