omuralievemil
07-05-2002, 02:51 AM
I have taken the sample code from this website to read registry values. Here it is:
' Start code
Option Explicit
Dim WSHShell, RegKey, RegKey1, OperatingSystem, Owner, Processor1, ProcessorArch
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\Software\Microsoft\Windows\CurrentVersion\"
RegKey1="HKLM\Hardware\Description\System\CentralProcessor\ 0\"
OperatingSystem = WSHShell.RegRead(RegKey & "ProductName")
Owner = WSHShell.RegRead(RegKey & "RegisteredOwner")
Processor1=WSHShell.RegRead(RegKey1 & "VendorIdentifier")
ProcessorArch=WSHShell.RegRead(RegKey1 & "Identifier")
WScript.echo "OperatingSystem: " & OperatingSystem & vbNewline &_
"Registered Owner: " & Owner & vbNewline &_
"Processor: " & Processor1 & vbNewline &_
"Processor Architecture: " & ProcessorArch
' End code
The code works nicely only if the values are present in the registry. If at least one registry value can not be found (the key or the value is not in the registry), it throws an error:
Error: Unable to open registry key
Code: 80070002
I would appreciate for help what to add into my code to avoid this error and just skip this registry value if it is not present in the registry. I suspect it has something to do with conditional If..........Then....., but don't know how to write it.
Thanks,
Emil
' Start code
Option Explicit
Dim WSHShell, RegKey, RegKey1, OperatingSystem, Owner, Processor1, ProcessorArch
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\Software\Microsoft\Windows\CurrentVersion\"
RegKey1="HKLM\Hardware\Description\System\CentralProcessor\ 0\"
OperatingSystem = WSHShell.RegRead(RegKey & "ProductName")
Owner = WSHShell.RegRead(RegKey & "RegisteredOwner")
Processor1=WSHShell.RegRead(RegKey1 & "VendorIdentifier")
ProcessorArch=WSHShell.RegRead(RegKey1 & "Identifier")
WScript.echo "OperatingSystem: " & OperatingSystem & vbNewline &_
"Registered Owner: " & Owner & vbNewline &_
"Processor: " & Processor1 & vbNewline &_
"Processor Architecture: " & ProcessorArch
' End code
The code works nicely only if the values are present in the registry. If at least one registry value can not be found (the key or the value is not in the registry), it throws an error:
Error: Unable to open registry key
Code: 80070002
I would appreciate for help what to add into my code to avoid this error and just skip this registry value if it is not present in the registry. I suspect it has something to do with conditional If..........Then....., but don't know how to write it.
Thanks,
Emil