gpt4 book ai didi

powershell - 使用 Powershell 创建注册表项

转载 作者:行者123 更新时间:2023-12-03 09:40:20 24 4
gpt4 key购买 nike

我正在尝试使用 powershell 检查注册表中是否存在 key 结构。如果结构不存在,我需要创建它,然后我需要在结束文件夹中创建 key 。如果我单独运行片段来创建 key ,它们就可以创建得很好。但是运行块本身(确保在注册表中手动确保键不存在)它不会创建文件夹结构。不确定是什么问题。任何帮助将不胜感激。代码如下:

$Registry_Paths = "hkcu:\Software\Microsoft\Office\14.0", "hkcu:\Software\Microsoft\Office\14.0\Groove", "hkcu:\Software\Microsoft\Office\14.0\Groove\Development"

foreach($Registry_Path in $Registry_Paths)
{
$Test_Path_Result = Test-Path -Path $Registry_Path
if($Test_Path_Result -eq $false)
{
$Registry_Key_Log += "Warning: No registry key path found at " + $Registry_Path +"`n"
$Registry_Key_Log += "Creating key now for " + $Registry_Path + "`n" + "`n"

if($Registry_Path -eq "hkcu:\Software\Microsoft\Office\14.0")
{
try{
New-Item -Path "HKCU:\Software\Microsoft\Office\14.0" -ItemType Key
}
catch
{
$Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
$Error_Log += $_.exception.message
}

}
if($Registry_Path -eq "hcku:\Software\Microsoft\Office\14.0\Groove")
{
try{
New-Item -Path "HKCU:\Software\Microsoft\Office\14.0\Groove" -ItemType Key
}
catch
{
$Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
$Error_Log += $_.exception.message
}
}
if($Registry_Path -eq "hcku:\Software\Microsoft\Office\14.0\Groove\Development")
{
try{
New-Item -Path "HKCU:\Software\Microsoft\Office\14.0\Groove\Development" -ItemType Key
New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 00000001 -PropertyType dword -Name "EnableReleaseBuildDebugOutput"
New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 1 -Name "TraceIdentityMessaging"
New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 00000001 -PropertyType dword -Name "TraceTelespaceFetch"
New-ItemProperty -Path "hkcu:\Software\Microsoft\Office\14.0\Groove\Development" -Value 1 -Name "TraceConnectSequence"

}
catch
{
$Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
$Error_Log += $_.exception.message
}
}

}
}

最佳答案

这是我的方法。

$Key = "HKEY_CURRENT_USER\TEST"
If ( -Not ( Test-Path "Registry::$Key")){New-Item -Path "Registry::$Key" -ItemType RegistryKey -Force}
Set-ItemProperty -path "Registry::$Key" -Name "Less" -Type "String" -Value "Less"

关于powershell - 使用 Powershell 创建注册表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26707029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com