Skip to content

Commit

Permalink
Merge pull request #1909 from vanceism7/RegistryModule
Browse files Browse the repository at this point in the history
Registry module
  • Loading branch information
matthid authored May 9, 2018
2 parents 4b195ee + 9845eba commit d7b430b
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 43 deletions.
65 changes: 40 additions & 25 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Tools.Pickles", "src/app/Fake.Tools.Pickles/Fake.Tools.Pickles.fsproj", "{2EC1798B-3AD5-42FE-9406-F358B995ACC3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{03CB61B6-EBB8-4C4A-B6A3-0D84D1F78A92}"
ProjectSection(SolutionItems) = preProject
build.fsx = build.fsx
EndProjectSection
ProjectSection(SolutionItems) = preProject
build.fsx = build.fsx
EndProjectSection
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Windows.Registry", "src/app/Fake.Windows.Registry/Fake.Windows.Registry.fsproj", "{71259EF7-41FD-4068-BD85-E4C7F67EAC25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -307,6 +309,18 @@ Global
{93F1A71E-54E2-4C65-BB1E-1D499890317F}.Release|x64.Build.0 = Release|Any CPU
{93F1A71E-54E2-4C65-BB1E-1D499890317F}.Release|x86.ActiveCfg = Release|Any CPU
{93F1A71E-54E2-4C65-BB1E-1D499890317F}.Release|x86.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x64.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x64.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x86.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x86.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|Any CPU.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x64.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x64.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x86.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x86.Build.0 = Release|Any CPU
{C1B87E1F-8D0D-4A78-9A24-9D5D38B7E9A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1B87E1F-8D0D-4A78-9A24-9D5D38B7E9A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1B87E1F-8D0D-4A78-9A24-9D5D38B7E9A8}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -703,18 +717,6 @@ Global
{77E0066D-A04D-445B-B036-9008A40F8A44}.Release|x64.Build.0 = Release|Any CPU
{77E0066D-A04D-445B-B036-9008A40F8A44}.Release|x86.ActiveCfg = Release|Any CPU
{77E0066D-A04D-445B-B036-9008A40F8A44}.Release|x86.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x64.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x64.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x86.ActiveCfg = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Debug|x86.Build.0 = Debug|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|Any CPU.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x64.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x64.Build.0 = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x86.ActiveCfg = Release|Any CPU
{819E2756-7BEE-4FCD-BA08-7BF323405CBE}.Release|x86.Build.0 = Release|Any CPU
{B636A082-4DB4-439D-8A37-E5214BDC00A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B636A082-4DB4-439D-8A37-E5214BDC00A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B636A082-4DB4-439D-8A37-E5214BDC00A3}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -753,16 +755,16 @@ Global
{3BC4A91C-3381-4BF9-BF11-8E06706CF878}.Release|x86.Build.0 = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x64.ActiveCfg = Debug|x64
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x64.Build.0 = Debug|x64
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x86.ActiveCfg = Debug|x86
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x86.Build.0 = Debug|x86
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x64.ActiveCfg = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x64.Build.0 = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x86.ActiveCfg = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Debug|x86.Build.0 = Debug|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|Any CPU.Build.0 = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x64.ActiveCfg = Release|x64
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x64.Build.0 = Release|x64
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x86.ActiveCfg = Release|x86
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x86.Build.0 = Release|x86
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x64.ActiveCfg = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x64.Build.0 = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x86.ActiveCfg = Release|Any CPU
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D}.Release|x86.Build.0 = Release|Any CPU
{4E702236-A2B1-4920-B56D-4746CC0726D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E702236-A2B1-4920-B56D-4746CC0726D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E702236-A2B1-4920-B56D-4746CC0726D3}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -811,6 +813,18 @@ Global
{2EC1798B-3AD5-42FE-9406-F358B995ACC3}.Release|x64.Build.0 = Release|Any CPU
{2EC1798B-3AD5-42FE-9406-F358B995ACC3}.Release|x86.ActiveCfg = Release|Any CPU
{2EC1798B-3AD5-42FE-9406-F358B995ACC3}.Release|x86.Build.0 = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|x64.ActiveCfg = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|x64.Build.0 = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|x86.ActiveCfg = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Debug|x86.Build.0 = Debug|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|Any CPU.Build.0 = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|x64.ActiveCfg = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|x64.Build.0 = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|x86.ActiveCfg = Release|Any CPU
{71259EF7-41FD-4068-BD85-E4C7F67EAC25}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -828,9 +842,9 @@ Global
{C3C12DCE-7AC4-4E97-A7FC-49189D218885} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{BB293F2E-C3BD-4F1C-8345-8AEF01998D2C} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{B2C0063A-FC66-4883-BB69-B1DBE6BF9CA2} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{D8CFE7F9-8E14-4B22-9729-7FF431AFE36B} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{64195C50-E138-4218-A7CE-13CD4565B87E} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{93F1A71E-54E2-4C65-BB1E-1D499890317F} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{819E2756-7BEE-4FCD-BA08-7BF323405CBE} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{C1B87E1F-8D0D-4A78-9A24-9D5D38B7E9A8} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{75C9DD21-B4EA-4117-BF4F-AFE777A80B5B} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{21E2FE31-4E7C-489E-8215-9303108A2F39} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
Expand Down Expand Up @@ -866,14 +880,15 @@ Global
{E09B72E4-D890-46A8-8D14-7367C2E23E9D} = {539D7B9A-18A1-4D79-86AB-C8B48090CA84}
{8561A35A-C2A4-43C7-A938-CB35A7747121} = {E09B72E4-D890-46A8-8D14-7367C2E23E9D}
{77E0066D-A04D-445B-B036-9008A40F8A44} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{819E2756-7BEE-4FCD-BA08-7BF323405CBE} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{B636A082-4DB4-439D-8A37-E5214BDC00A3} = {901F162F-8925-4390-89C5-9EE2C343F744}
{DE7579F2-C20F-4C35-BC04-C10362912243} = {901F162F-8925-4390-89C5-9EE2C343F744}
{3BC4A91C-3381-4BF9-BF11-8E06706CF878} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{3C27E2CA-98DC-40ED-B334-87B84D7F3E0D} = {901F162F-8925-4390-89C5-9EE2C343F744}
{4E702236-A2B1-4920-B56D-4746CC0726D3} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{DA58D728-C36A-4DC7-8D92-F2BA13667EA5} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{D8CFE7F9-8E14-4B22-9729-7FF431AFE36B} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{2EC1798B-3AD5-42FE-9406-F358B995ACC3} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{71259EF7-41FD-4068-BD85-E4C7F67EAC25} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ let dotnetAssemblyInfos =
"Fake.Testing.Common", "Common testing data types"
"Fake.Tracing.NAntXml", "NAntXml"
"Fake.Windows.Chocolatey", "Running and packaging with Chocolatey"
"Fake.Windows.Registry", "CRUD functionality for Windows registry"
"Fake.Testing.SonarQube", "Analyzing your project with SonarQube"
"Fake.Testing.ReportGenerator", "Convert XML coverage output to various formats"
"Fake.DotNet.Testing.OpenCover", "Code coverage with OpenCover"
Expand Down
3 changes: 3 additions & 0 deletions help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@
<ul>
<li><a href="/windows-chocolatey.html">Chocolatey</a></li>
</ul>
<ul>
<li><a href="/apidocs/v5/fake-windows-registry.html">Registry</a></li>
</ul>
</li>
<li>
<a href="/apidocs/v5/legacy/index.html#Fake">Legacy / Not Migrated</a>
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.Windows.Registry/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# CRUD functionality for Windows registry")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0-beta025")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# CRUD functionality for Windows registry"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0-beta025"
let [<Literal>] AssemblyFileVersion = "5.0.0"
18 changes: 18 additions & 0 deletions src/app/Fake.Windows.Registry/Fake.Windows.Registry.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<AssemblyName>Fake.Windows.Registry</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);FX_NO_REMOTING;USE_ASYNC_LOCAL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Registry.fs" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
153 changes: 153 additions & 0 deletions src/app/Fake.Windows.Registry/Registry.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/// Contains functions which allow to read and write information from/to the registry.
///
/// ## Sample
///
/// #### Create a subkey
/// let subkey = "Company/MyApp"
/// Registry.createRegistrySubKey Registry.HKEYCurrentUser subkey
///
/// #### Write a key-value pair to a subkey
/// Registry.setRegistryValue Registry.HKEYCurrentUser subkey "AppType" "Premium"
/// Registry.setRegistryValue Registry.HKEYCurrentUser subkey "Version" "1.0.4"
///
/// #### Get a list of key-value names in a subkey
/// let values = Registry.getRegistryValueNames Registry.HKEYCurrentUser subkey
/// values |> Array.iter (Trace.trace << (sprintf "Found value name: %s!"))
///
/// #### Read the value of a key-value pair
/// let AppType = Registry.getRegistryValue Registry.HKEYCurrentUser subkey values.[0]
/// Trace.trace (sprintf "You are running the %s version" AppType)
///
/// #### Check if a value exists within a subkey
/// let exists b = if b then Trace.trace "It exists!" else Trace.trace "It doesn't exist!"
/// exists <| Registry.valueExistsForKey Registry.HKEYCurrentUser subkey "DateCreated"
/// exists <| Registry.valueExistsForKey Registry.HKEYCurrentUser subkey "Version"
///
/// #### Delete a key-value pair from a subkey
/// Registry.deleteRegistryValue Registry.HKEYCurrentUser subkey "AppType"
///
/// #### Delete a subkey
/// Registry.deleteRegistrySubKey Registry.HKEYCurrentUser subkey
[<RequireQualifiedAccess>]
module Fake.Windows.Registry

open Microsoft.Win32

/// Registry base keys.
type RegistryBaseKey =
| HKEYLocalMachine
| HKEYClassesRoot
| HKEYUsers
| HKEYCurrentUser
| HKEYCurrentConfig
| HKEYPerformanceData

(*
Lower level Registry Queries
(Should these be private?)
*)
/// Maps the RegistryBaseKey to a RegistryKey
/// [omit]
let getKey name =
match name with
| HKEYLocalMachine -> Registry.LocalMachine
| HKEYClassesRoot -> Registry.ClassesRoot
| HKEYUsers -> Registry.Users
| HKEYCurrentUser -> Registry.CurrentUser
| 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 =
match name with
| HKEYLocalMachine -> RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
| HKEYClassesRoot -> RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry32)
| HKEYUsers -> RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry32)
| HKEYCurrentUser -> RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32)
| HKEYCurrentConfig -> RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry32)
| HKEYPerformanceData -> RegistryKey.OpenBaseKey(RegistryHive.PerformanceData, RegistryView.Registry32)

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

/// Gets a registry 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)
if (isNull >> not) x64BitKey then x64BitKey else
(get32BitKey baseKey).OpenSubKey(subKey, writePermission) // fall back to 32 bit

(*
Registry Value Commands
*)
/// Gets a registry value as string
let getRegistryValue baseKey subKey name =
use key = getRegistryKey baseKey subKey false
if isNull key then
failwithf "Registry subkey %s could not be found for key %A" subKey baseKey
let value = key.GetValue name
if isNull value then
failwithf "Registry value is null for key %s" (key.ToString())
value.ToString()

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

/// Sets a registry value
let setRegistryValue<'T> baseKey subKey name (value : 'T) =
use key = getRegistryKey baseKey subKey true
key.SetValue(name, value)

/// Deletes the registry value from its key
let deleteRegistryValue baseKey subKey name =
use key = getRegistryKey baseKey subKey true
key.DeleteValue name

/// Returns all the value names of a registry key
let getRegistryValueNames baseKey subKey =
use key = getRegistryKey baseKey subKey false
key.GetValueNames()

/// Returns whether or not a registry value name exists for a key
let valueExistsForKey = fun baseKey subKey name ->
getRegistryValueNames baseKey subKey
|> Seq.exists (fun n -> n = name)

(*
Subkey Commands
*)
/// Create a registry subKey
let createRegistrySubKey baseKey subKey =
use key = getKey baseKey
key.CreateSubKey subKey |> ignore

/// Deletes a registry subKey
let deleteRegistrySubKey baseKey subKey =
use key = getKey baseKey
key.DeleteSubKey subKey

/// Returns all the subKey names of a registry key
let getRegistrySubKeyNames baseKey subKey =
use key = getRegistryKey baseKey subKey false
key.GetSubKeyNames()

5 changes: 5 additions & 0 deletions src/app/Fake.Windows.Registry/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group netcore

FSharp.Core
NETStandard.Library
Microsoft.Win32.Registry
5 changes: 4 additions & 1 deletion src/legacy/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@
<Compile Include="..\..\app\Fake.Sql.DacPac\Sql.DacPac.fs">
<Link>Fake.Sql.DacPac\Sql.DacPac.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.Windows.Registry\Registry.fs">
<Link>Fake.Windows.Registry\Registry.fs</Link>
</Compile>
<Compile Include="UserInputHelper.fs" />
<Compile Include="CSharpHelper.fs" />
<Compile Include="EnvironmentHelper.fs" />
Expand Down Expand Up @@ -2702,4 +2705,4 @@
</When>
</Choose>
<Import Project="..\..\..\packages\NETStandard.Library\build\$(__paket__NETStandard_Library_targets).targets" Condition="Exists('..\..\..\packages\NETStandard.Library\build\$(__paket__NETStandard_Library_targets).targets')" Label="Paket" />
</Project>
</Project>
Loading

0 comments on commit d7b430b

Please sign in to comment.