---
title: About the registry_key Resource
platform: windows
---
# registry_key
Use the `registry_key` InSpec audit resource to test key values in the Windows registry.
## Syntax
A `registry_key` resource block declares the item in the Windows registry, the path to a setting under that item, and then one (or more) name/value pairs to be tested.
Use a registry key name and path:
describe registry_key('Task Scheduler','HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') do
its('Start') { should eq 2 }
end
Use only a registry key path:
describe registry_key('Task Scheduler','HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule') do
its('Start') { should eq 2 }
end
Or use a Ruby Hash:
describe registry_key({
name: 'Task Scheduler',
hive: 'HKEY_LOCAL_MACHINE',
key: '\SYSTEM\CurrentControlSet\services\Schedule'
}) do
its('Start') { should eq 2 }
end
### Registry Key Path Separators
A Windows registry key can be used as a string in Ruby code, such as when a registry key is used as the name of a recipe. In Ruby, when a registry key is enclosed in a double-quoted string (`" "`), the same backslash character (`\`) that is used to define the registry key path separator is also used in Ruby to define an escape character. Therefore, the registry key path separators must be escaped when they are enclosed in a double-quoted string. For example, the following registry key:
HKCU\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Themes
may be enclosed in a single-quoted string with a single backslash:
'HKCU\SOFTWARE\path\to\key\Themes'
or may be enclosed in a double-quoted string with an extra backslash as an escape character:
"HKCU\\SOFTWARE\\path\\to\\key\\Themes"
Please make sure that you use backslashes instead of forward slashes. Forward slashes will not work for registry keys.
# The following will not work: # describe registry_key('HKLM/SOFTWARE/Microsoft/NET Framework Setup/NDP/v4/Full/1033') do # its('Release') { should eq 378675 } # end # You should use: describe registry_key('HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\1033') do its('Release') { should eq 378675 } end
Any name with a dot will not work as expected: its('explorer.exe') { should eq 'test' }
. For details, see https://github.com/inspec/inspec/issues/1281