$env:tmp
[Environment]::GetEnvironmentVariable('tmp', 'User')
(get-item hkcu:\Environment).GetValue('tmp')
上面的所有PowerShell代码段都返回C:\Users\Roman\AppData\Local\Temp
值。我知道这个值应该是%USERPROFILE%\AppData\Local\Temp
(我可以在regedit和环境变量窗口中看到)。
我需要知道“原始”值,而不是“解析”值。如何在PowerShell中读取此值?
谢谢。
发布于 2011-01-04 22:00:37
最后,我找到了一个适合我的解决方案:
(get-item hkcu:\Environment).GetValue('tmp', $null, 'DoNotExpandEnvironmentNames')
我在编写以下PowerShell/C#代码后发现了这个GetValue重载:
$reg = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Environment", $true);
$val = $reg.GetValue('tmp', $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$val
$reg.Close()
https://stackoverflow.com/questions/4598532
复制