[英]Checking for Registry Key, then incrementing in Powershell
i'm trying to check if a reg key exist and then increment a reg key if it does. 我正在尝试检查是否存在注册密钥,然后增加一个注册密钥(如果存在)。 I confirmed that i can set the registry value if i just put the value in directly.
我确认如果我直接输入值,我可以设置注册表值。 ie putting in the value 3.
即投入价值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
is a number so Test-Path $value
is always going to be false. $value
是一个数字,因此Test-Path $value
总是为假。 Which path do you want to check? 你想检查哪条路? The file system path c:\\windows\\system32\\test.dll or the registry key path?
文件系统路径c:\\ windows \\ system32 \\ test.dll或注册表项路径? If it is the registry key path, you know it exists because it you did a Get-ItemProperty on it.
如果它是注册表键路径,您知道它存在,因为您在其上执行了Get-ItemProperty。
As administrator, Change $dllToCheck
with your own value and try this : 作为管理员,使用您自己的值更改
$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.