| 1 |
// Licensed to the .NET Foundation under one or more agreements. |
| 2 |
// The .NET Foundation licenses this file to you under the MIT license. |
| 3 |
// See the LICENSE file in the project root for more information. |
| 4 |
|
| 5 |
using System; |
| 6 |
using System.Runtime.InteropServices; |
| 7 |
using Microsoft.Win32.SafeHandles; |
| 8 |
|
| 9 |
namespace Microsoft.Win32.RegistryTests |
| 10 |
{ |
| 11 |
internal static class Helpers |
| 12 |
{ |
| 13 |
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueW", SetLastError = true)] |
| 14 |
private static extern int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored); |
| 15 |
|
| 16 |
internal static bool SetDefaultValue(this RegistryKey key, string value) |
| 17 |
{ |
| 18 |
const int REG_SZ = 1; |
| 19 |
return RegSetValue(key.Handle, null, REG_SZ, value, 0) == 0; |
| 20 |
} |
| 21 |
|
| 22 |
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)] |
| 23 |
private static extern int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, [Out] byte[] value, ref int size); |
| 24 |
|
| 25 |
internal static bool IsDefaultValueSet(this RegistryKey key) |
| 26 |
{ |
| 27 |
const int ERROR_FILE_NOT_FOUND = 2; |
| 28 |
byte[] b = new byte[4]; |
| 29 |
int size = 4; |
| 30 |
return RegQueryValueEx(key.Handle, null, null, IntPtr.Zero, b, ref size) != ERROR_FILE_NOT_FOUND; |
| 31 |
} |
| 32 |
|
| 33 |
[DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)] |
| 34 |
internal static extern bool SetEnvironmentVariable(string lpName, string lpValue); |
| 35 |
} |
| 36 |
} |