检查远程计算机中是否存在注册表路径 [英] Check if a Registry Path Exists in Remote Machine
问题描述
我使用 Power Shell 使用此命令检查路径是否存在.powershell test-path "HKCU:\Software\Microsoft\Windows" 现在如何将其扩展到远程机器.如果我想在远程计算机中测试注册表路径,语法是什么,我尝试了 powershell test-path "\\machinename\HKCU:\Software\Microsoft\Windows" 但它不起作用.建议一些方法来测试它.
I have used Power Shell to check if a path exists using this command . powershell test-path "HKCU:\Software\Microsoft\Windows" now how can the same be extended to remote machine. What is the syntax if i want to test a registry path in Remote machine, i tried powershell test-path "\\machinename\HKCU:\Software\Microsoft\Windows" and its not working. Suggest some way to test it.
推荐答案
您可以按照此处的说明访问它:http://powershell.com/cs/blogs/tips/archive/2011/02/15/accessing-registry-remote.aspx
You can access it as outlined here: http://powershell.com/cs/blogs/tips/archive/2011/02/15/accessing-registry-remote.aspx
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', 'server123')
$key = $reg.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')
$key.GetSubKeyNames() | ForEach-Object {
$subkey = $key.OpenSubKey($_)
$i = @{}
$i.Name = $subkey.GetValue('DisplayName')
$i.Version = $subkey.GetValue('DisplayVersion')
New-Object PSObject -Property $i
$subkey.Close()
}
$key.Close()
$reg.Close()
另一种方法是在远程机器上启用 PSRemoting 并使用 invoke-command
并有效地运行与在本地机器上运行的命令相同的命令.
An alternative is to enable PSRemoting and use invoke-command
on the remote machine and effectively run the same command as what you would run on the local box.
这篇关于检查远程计算机中是否存在注册表路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!