Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegistryKey for a 64bit System #580

Merged
merged 1 commit into from
Oct 28, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/app/FakeLib/RegistryHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ let getKey name =
| HKEYCurrentConfig -> Registry.CurrentConfig
| HKEYPerformanceData -> Registry.PerformanceData

/// Maps the RegistryBaseKey to a RegistryKey for a 64bit System
/// [omit]
let get64BitKey name =
match name with
| HKEYLocalMachine -> RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
| HKEYClassesRoot -> RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64)
| HKEYUsers -> RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64)
| HKEYCurrentUser -> RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)
| HKEYCurrentConfig -> RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry64)
| HKEYPerformanceData -> RegistryKey.OpenBaseKey(RegistryHive.PerformanceData, RegistryView.Registry64)

/// Maps the RegistryBaseKey to a RegistryKey for a 32bit System
/// [omit]
let get32BitKey name =
Expand All @@ -35,6 +46,10 @@ let get32BitKey name =
| HKEYCurrentConfig -> RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry32)
| HKEYPerformanceData -> RegistryKey.OpenBaseKey(RegistryHive.PerformanceData, RegistryView.Registry32)

/// Gets a 64-bit registy key
let getRegistryKey64 baseKey subKey (writePermission : bool) =
(get64BitKey baseKey).OpenSubKey(subKey, writePermission)

/// Gets a registy key and falls back to 32 bit if the 64bit key is not there
let getRegistryKey baseKey subKey (writePermission : bool) =
let x64BitKey = (getKey baseKey).OpenSubKey(subKey, writePermission)
Expand All @@ -51,6 +66,16 @@ let getRegistryValue baseKey subKey value =
failwithf "Registry value is null for key %s" (key.ToString())
value.ToString()

/// Gets a registy value as string
let getRegistryValue64 baseKey subKey value =
use key = getRegistryKey64 baseKey subKey false
if key = null then
failwithf "Registry subkey %s could not be found for key %A" subKey baseKey
let value = key.GetValue value
if value = null then
failwithf "Registry value is null for key %s" (key.ToString())
value.ToString()

/// create a registry subKey
let createRegistrySubKey baseKey subKey = (getKey baseKey).CreateSubKey subKey |> ignore

Expand Down