当前位置: 代码网 > it编程>前端脚本>Powershell > 使用PowerShell修改注册表

使用PowerShell修改注册表

2024年05月18日 Powershell 我要评论
下面的例子里, powershell修改了注册表键值, 完成了security loop disable, 和loopbackcheck disable.实例给大家了,下面分享一些powershell

下面的例子里, powershell修改了注册表键值, 完成了security loop disable, 和loopbackcheck disable.

实例给大家了,下面分享一些powershell操作注册表的方法吧

访问注册表键值

在powershell中,用户可以通过类似于hkcu:(作为hkey_current_user)和hklm:(代表hkey_local_matchine)的虚拟驱动器访问注册表键值。
如:dir registry::hkey_local_machine\software
通过这种方式用户可以很容易的复制、粘贴注册表内的键值,用户可以通过下面的命令获取已经注册的文件后缀:
dir registry::hkey_classes_root\.* -name | sort-object

读取注册表键值

在powershell中,用户能够以虚拟驱动器的形式来处理注册表的内容
下面的get-regidtryvalues函数列举存储在一个注册表键值下的所有键值,完整代码如下所示:

 
function get-registryvalues($key) { 
         (get-item $key).getvaluenames() 
}

get-registryvalues hklm:\software\microsoft\windows\currentversion

get-registryvalue读取任意注册表键值并返回其内容,完整代码如下所示:

function get-registryvalue($key, $value) { 
         (get-itemproperty $key $value).$value 
} 
get-registryvalue ' hklm:\software\microsoft\windows\currentversion' ` 


sm_gamesname

写入注册表键值

添加或修改注册表键值在powershell中也是很方便的就可以完成的,下面创建名为set-registryvalue函数用来操作注册表键值,以下是完整的代码:

function set-registryvalue($key, $name, $value, $type="string") { 
 if ((test-path $key) -eq $false) { md $key | out-null } 
    set-itemproperty $key $name $value -type $type 
 } 
  set-registryvalue hkcu:\software\testabc myvalue hello 
  set-registryvalue hkcu:\software\testabc myvalue 12 dword 
  set-registryvalue hkcu:\software\testabc myvalue ` 
([byte[]][char[]]"hello") binary

移除注册表键值

通过remove-item删除目标注册表键,函数remove-registrykey的完整代码如下所示:

function remove-registrykey($key) { 
remove-item $key -force 
}

通过remove-itemproperty函数删除注册表值,完整的代码如下所示:

function remove-registryvalue($key, $value) { 
remove-itemproperty $key $value 
}

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com