开发者

PowerShell: Get 'tmp' environment variable raw value

开发者 https://www.devze.com 2023-02-02 04:46 出处:网络
$env:tmp [Environment]::GetEnvironmentVariable(\'tmp\', \'User\') (get-item hkcu:\\Environment).GetValue(\'tmp\')
$env:tmp

[Environment]::GetEnvironmentVariable('tmp', 'User')

(get-item hkcu:\Environment).GetValue('tmp')

All above PowerShell snippets return C:\Users\Roman\AppData\Local\Temp value. I know that the value should be%USERPROFILE%\AppData\Local\Temp (this I can see in regedit and in Environment Variables window).

I开发者_JAVA技巧 need to know 'original', but not 'resolved' value. How can I read this value in PowerShell?

Thanks.


Finally I have found a solution that works for me:

(get-item hkcu:\Environment).GetValue('tmp', $null, 'DoNotExpandEnvironmentNames')

I discovered this GetValue overload after writing following PowerShell/C# code:

$reg = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Environment", $true);
$val = $reg.GetValue('tmp', $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$val
$reg.Close()
0

精彩评论

暂无评论...
验证码 换一张
取 消