繁体   English   中英

检查注册表项,然后在Powershell中递增

[英]Checking for Registry Key, then incrementing in Powershell

我正在尝试检查是否存在注册密钥,然后增加一个注册密钥(如果存在)。 我确认如果我直接输入值,我可以设置注册表值。 即投入价值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"
    }

$value是一个数字,因此Test-Path $value总是为假。 你想检查哪条路? 文件系统路径c:\\ windows \\ system32 \\ test.dll或注册表项路径? 如果它是注册表键路径,您知道它存在,因为您在其上执行了Get-ItemProperty。

作为管理员,使用您自己的值更改$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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM