[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载代码] [PowerShell每日技巧]读取包含扩展字符(如%SystemRoot%)的注册表键值(20140210)

When you read a Registry value of type StringExpand, it will always automatically expand any environment variables contained in the text.

This example will read the system device path from your Registry:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-ItemProperty -Path $path
  3. $key.DevicePath
复制代码
The result will be an actual path. That is OK unless you wanted to get the original (unexpanded) Registry value. Here is the example that reads the original value:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-Item -Path $path
  3. $key.GetValue('DevicePath', '', 'DoNotExpandEnvironmentNames')
复制代码
Accessing Registry values this way will get you another valuable piece of information: you can now also find out the value's data type:
  1. $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
  2. $key = Get-Item -Path $path
  3. $key.GetValueKind('DevicePath')
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/02/10/reading-stringexpand-registry-values.aspx

返回列表