Skip to content

Commit

Permalink
Add try for registry access
Browse files Browse the repository at this point in the history
  • Loading branch information
dkirov-dd committed Nov 15, 2024
1 parent 3e38eb4 commit 8fbe142
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,14 @@ def enable_fips(self, path_to_embedded=None):

registry_hive = winreg.HKEY_LOCAL_MACHINE
registry_path = r"SOFTWARE\Datadog\Datadog Agent"
registry_key = winreg.OpenKey(registry_hive, registry_path, 0, winreg.KEY_READ)
# The Agent install path is stored in a Windows registry
path_to_agent, _ = winreg.QueryValueEx(registry_key, "InstallPath")
winreg.CloseKey(registry_key)
try:
registry_key = winreg.OpenKey(registry_hive, registry_path, 0, winreg.KEY_READ)
# The Agent install path is stored in a Windows registry
path_to_agent, _ = winreg.QueryValueEx(registry_key, "InstallPath")
winreg.CloseKey(registry_key)
except OSError as e:
logging.error(f'The install path could not be read from the \"{registry_path}\" registry.')
raise e
path_to_embedded = Path(path_to_agent) / "embedded3"
else: # Linux
path_to_embedded = Path('/opt/datadog-agent/embedded')
Expand Down

0 comments on commit 8fbe142

Please sign in to comment.