我正在尝试检查是否存在reg密钥,然后增加一个reg密钥。我确认如果我直接输入值,我可以设置注册表值。即输入值3。
$path = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDLLs"
$psv = Get-ItemProperty -path $path
$value = $psv."c:\windows\system32\test.dll"
if(!(Test-Path $value))
{
Set-ItemProperty -path $path -name $key -Type DWORD -value $value++
}
Else
{
echo "error 1"
}
答案 0 :(得分:1)
$value
是一个数字,因此Test-Path $value
总是错误的。你想检查哪条路?文件系统路径c:\ windows \ system32 \ test.dll或注册表项路径?如果它是注册表键路径,您知道它存在,因为您在其上执行了Get-ItemProperty。
答案 1 :(得分:1)
作为管理员,请使用您自己的值更改$dllToCheck
并尝试以下操作:
$regPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDLLs"
$dllToCheck = "C:\Program Files (x86)\Hewlett-Packard\Shared\CaslVer.exe"
$exist = get-itemproperty $regPath -name $dllToCheck -ErrorAction silentlycontinue
if ($exist -ne $null)
{
$currentValue = $exist.$dllToCheck
$nextValue = $currentValue + 1
Set-ItemProperty $regPath -name $dllToCheck -Value $nextValue
}