Getting registry value using WMI

后端 未结 3 1184
终归单人心
终归单人心 2021-01-28 00:43

I\'m getting an exception which I can\'t find documented anywhere. Here is the exception:

The following exception occurred while retrieving the type name hierarc         


        
相关标签:
3条回答
  • 2021-01-28 00:56

    don't you over complicate things ? all of these to read a value from registry ? what about someting like that

    icm -ComputerName $endpoint -ScriptBlock {Get-ItemProperty HKLM:\software\7-zip\ |select path} 
    
    0 讨论(0)
  • 2021-01-28 00:59

    Either method works, but using the measure-command I found the example that icm was 10 times slower, 0.47 seconds versus 4.8 seconds using ICM.

    0 讨论(0)
  • 2021-01-28 01:09

    If you must use WMI use something like this (taken from the Scripting Guy blog):

    $endpoint = 'someEndpointName'
    
    $basekey  = [uint32]'0x80000002'
    $subkey   = 'SOFTWARE\Company\EOS Version'
    $value    = 'Build S Version'
    
    $reg = [wmiclass]"\\$endpoint\root\default:StdRegProv"
    $buildSVersion = $reg.GetStringValue($basekey, $subkey, $value).sValue
    

    Personally I'd prefer using remote registry access, though:

    $endpoint = 'someEndpointName'
    
    $basekey  = 'LocalMachine'
    $subkey   = 'SOFTWARE\Company\EOS Version'
    $value    = 'Build S Version'
    
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($basekey, $endpoint)
    $key = $reg.OpenSubKey($subkey, $true)
    $buildSVersion = $key.GetValue($value)
    
    0 讨论(0)
提交回复
热议问题