42 people like it.

Getting a key from Windows registry

F# code to fetch a registry key

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
let REGISTRYSOFTWARE = "Software";
let REGISTRYMYPATH = "MySoftware";

let internal GetRegistryValue key =
    use path1 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(REGISTRYSOFTWARE)
    match path1 with
    | null -> failwith("Access failed to registry: hklm\\"+REGISTRYSOFTWARE)
    | keyhklmsw -> 
        use path2 = keyhklmsw.OpenSubKey(REGISTRYMYPATH)
        match path2 with
        | null -> failwith("Access failed to registry: " + REGISTRYMYPATH)
        | keyhklmswmypath -> 
            match keyhklmswmypath.GetValue(key, null) with
            | null -> failwith("Path not found: " + key)
            | gotkey -> gotkey
val REGISTRYSOFTWARE : string

Full name: Script.REGISTRYSOFTWARE
val REGISTRYMYPATH : string

Full name: Script.REGISTRYMYPATH
val internal GetRegistryValue : key:string -> obj

Full name: Script.GetRegistryValue
val key : string
val path1 : Win32.RegistryKey
namespace Microsoft
namespace Microsoft.Win32
type Registry =
  static val CurrentUser : RegistryKey
  static val LocalMachine : RegistryKey
  static val ClassesRoot : RegistryKey
  static val Users : RegistryKey
  static val PerformanceData : RegistryKey
  static val CurrentConfig : RegistryKey
  static val DynData : RegistryKey
  static member GetValue : keyName:string * valueName:string * defaultValue:obj -> obj
  static member SetValue : keyName:string * valueName:string * value:obj -> unit + 1 overload

Full name: Microsoft.Win32.Registry
field Win32.Registry.LocalMachine
Win32.RegistryKey.OpenSubKey(name: string) : Win32.RegistryKey
Win32.RegistryKey.OpenSubKey(name: string, permissionCheck: Win32.RegistryKeyPermissionCheck) : Win32.RegistryKey
Win32.RegistryKey.OpenSubKey(name: string, writable: bool) : Win32.RegistryKey
Win32.RegistryKey.OpenSubKey(name: string, permissionCheck: Win32.RegistryKeyPermissionCheck, rights: System.Security.AccessControl.RegistryRights) : Win32.RegistryKey
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
val keyhklmsw : Win32.RegistryKey
val path2 : Win32.RegistryKey
val keyhklmswmypath : Win32.RegistryKey
Win32.RegistryKey.GetValue(name: string) : obj
Win32.RegistryKey.GetValue(name: string, defaultValue: obj) : obj
Win32.RegistryKey.GetValue(name: string, defaultValue: obj, options: Win32.RegistryValueOptions) : obj
val gotkey : obj
Raw view New version

More information

Link:http://fssnip.net/1m
Posted:5 years ago
Author:Tuomas Hietanen
Tags: Registry