4

我正在尝试从 .reg 文件中编辑现有的注册表项。我想将键的值更改为不同的值,即 reg_expand_sz 值(该值是文件路径)。我试着这样做:

Windows Registry Editor Version 5.00

["HKEY_CURRENT_USER\Control Panel\Cursors"]
"Arrow"=REG_EXPAND_SZ:"%SystemRoot%\System32\VIRUS\Virus\newArrow.cur"

这没有用。我应该怎么做?

4

4 回答 4

2

使用 PowerShell

sp 'hkcu:control panel/cursors' arrow `
  '%SystemRoot%/System32/VIRUS/Virus/newArrow.cur'

Set-ItemProperty

于 2013-05-15T03:39:08.897 回答
1

似乎windows(7)在那里接受十六进制值。理解它的最简单方法是手动编辑它,然后在 regedit 应用程序中进行导出。会告诉你该怎么做。

我做到了并且得到了这个并且它有效。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Cursors]
"Arrow"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
  00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,56,00,\
  49,00,52,00,55,00,53,00,5c,00,56,00,69,00,72,00,75,00,73,00,5c,00,6e,00,65,\
  00,77,00,41,00,72,00,72,00,6f,00,77,00,2e,00,63,00,75,00,72,00,00,00
于 2013-05-15T00:55:27.617 回答
1

REG_SZ:一个以 null 结尾的字符串。这将是 Unicode 或 ANSI 字符串,具体取决于您使用的是 Unicode 还是 ANSI 函数。

REG_EXPAND_SZ:一个以 null 结尾的字符串,其中包含对环境变量的未扩展引用(例如,“%PATH%”)。它将是 Unicode 或 ANSI 字符串,具体取决于您使用的是 Unicode 还是 ANSI 函数。要扩展环境变量引用,请使用 Expand EnvironmentStrings 函数

例如:C:\ (%HomeDrive%)

REG_SZ : @="C:\"

REG_EXPAND_SZ : @=hex(2):43,00,3a,00,5c,00,00,00

因此,您必须将REG_EXPAND_SZ用于包含对环境变量的未扩展引用的空终止字符串(例如 %HomeDrive% 、 %App% 、 %SystemRoot% ... )。

于 2014-06-02T21:10:00.633 回答
1

使用 powershell 很难避免变量的扩展。我正在使用的解决方案,调用RegistryKey.GetValue Method (String, Object, RegistryValueOptions)有点冗长,但它的基本原理在https://www.sepago.com/blog/2013/08/22/reading-中有很好的描述and-writing-regexpandsz-data-with-powershell

$Hive = [Microsoft.Win32.Registry]::LocalMachine
$keypath='SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems'
$Key = $Hive.OpenSubKey($keypath, $True)

# prevent expansion
$oldValue = $Key.GetValue($valueName, $False, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)

# update the value
$newValue = $oldValue -replace '(^.*SharedSection=\d+,\d+),(\d+) (.*$)', "`$1,$newHeap `$3"
$Key.SetValue($valueName, $newValue, [Microsoft.Win32.RegistryValueKind]::ExpandString)
于 2016-11-18T21:54:24.670 回答