本文整理汇总了C#中Microsoft.Win32.RegistryKey.CreateSubKey方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.CreateSubKey方法的具体用法?C# RegistryKey.CreateSubKey怎么用?C# RegistryKey.CreateSubKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.CreateSubKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRK
private void CreateRK(RegistryKey rk)
{
rk = rk.CreateSubKey(sProtocol);
rk.SetValue("URL Protocol", "");
rk = rk.CreateSubKey("Shell");
rk = rk.CreateSubKey("Open");
rk = rk.CreateSubKey("Command");
rk.SetValue(null,sExe);
}
示例2: initialize
public static void initialize()
{
RegistryKey software = Registry.CurrentUser.OpenSubKey("Software", true);
options = software.CreateSubKey("Changes Checker");
list = options.CreateSubKey("list");
hashes = options.CreateSubKey("hashes");
//times = options.CreateSubKey("times");
RegistryKey userMailBeep = Registry.CurrentUser.OpenSubKey("AppEvents")
.OpenSubKey("Schemes").OpenSubKey("Apps").OpenSubKey(".Default")
.OpenSubKey(".Default").OpenSubKey(".Current");
soundPath = userMailBeep.GetValue("").ToString();
userMailBeep.Close();
}
示例3: CopyKey
/// <summary>
/// Copies recursivelly the registry data from the source to the destination key.
/// </summary>
/// <param name="srcKey">The source key.</param>
/// <param name="srcPath">The source path.</param>
/// <param name="dstKey">The destination key.</param>
/// <param name="dstPath">The detination path.</param>
/// <param name="progress">A delegate to the progress.</param>
/// <returns><b>True</b> if the copy was successful, <b>false</b> otherwise.</returns>
public static bool CopyKey(RegistryKey srcKey, string srcPath, RegistryKey dstKey, string dstPath, Action<string, string> progress = null)
{
// Open the source key.
using (RegistryKey src = srcKey.OpenSubKey(srcPath, RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// If the source key is null, return.
if (null == src) return false;
// Create the destination key.
using (RegistryKey dst = dstKey.CreateSubKey(dstPath, RegistryKeyPermissionCheck.ReadWriteSubTree))
{
// If the destination key is null, return.
if (null == dst) return false;
// If the progress delegate is not null, update the progress.
if (null != progress) progress(src.Name, dst.Name);
// Copy all values.
foreach (string value in src.GetValueNames())
{
// Copy the values.
dst.SetValue(value, src.GetValue(value), src.GetValueKind(value));
}
// Perform a recursive copy of the registry keys.
foreach (string subkey in src.GetSubKeyNames())
{
// Copy the registry key.
RegistryExtensions.CopyKey(src, subkey, dst, subkey, progress);
}
return true;
}
}
}
示例4: SetRegistryData
public static void SetRegistryData(RegistryKey key, string path, string item, string value)
{
string[] keys = path.Split(new char[] {'/'},StringSplitOptions.RemoveEmptyEntries);
try
{
if (keys.Count() == 0)
{
key.SetValue(item, value);
key.Close();
}
else
{
string[] subKeys = key.GetSubKeyNames();
if (subKeys.Where(s => s.ToLowerInvariant() == keys[0].ToLowerInvariant()).FirstOrDefault() != null)
{
//Open subkey
RegistryKey sub = key.OpenSubKey(keys[0], (keys.Count() == 1));
if (keys.Length > 1)
SetRegistryData(sub, path.Substring(keys[0].Length + 1), item, value);
else
SetRegistryData(sub, string.Empty, item, value);
}
else
{
SetRegistryData(key.CreateSubKey(keys[0]), path.Substring(keys[0].Length + 1), item, value);
}
}
}
catch { }
}
示例5: Upgrade
public bool Upgrade(IIndentGuide service, RegistryKey root, string subkeyName)
{
int version;
using (var reg = root.OpenSubKey(subkeyName, false)) {
version = (reg == null) ? 0 : (int)reg.GetValue("Version", IndentGuidePackage.DEFAULT_VERSION);
}
if (version == 0 || version == IndentGuidePackage.Version) {
return false;
}
using (var reg = root.CreateSubKey(subkeyName)) {
if (version >= 0x000C0903) {
// Nothing to upgrade
} else if (version == 0x000C0902) {
UpgradeFrom_12_9_2(reg);
} else if (version >= 0x000C0000) {
// Nothing to upgrade
} else if (version >= 0x000B0901) {
UpgradeFrom_11_9_0(reg);
} else if (version >= 0x000A0901) {
UpgradeFrom_10_9_1(reg);
} else {
UpgradeFrom_Earlier(reg);
}
// Upgrading will make guides visible regardless of the
// previous setting.
reg.SetValue("Visible", 1);
}
return true;
}
示例6: initKeys
static void initKeys()
{
if (mainKey != null) return;
mainKey = Custom.BaseKey; // Registry.CurrentUser.CreateSubKey("SOFTWARE\\Repetier");
windowKey = mainKey.CreateSubKey("window");
}
示例7: PlConfigSlice
/// <summary>
/// Creates a new configuration slice instance.
/// </summary>
/// <param name="slice">The slice.</param>
/// <param name="rootKey">The root registry key.</param>
public PlConfigSlice(PlSlice slice, RegistryKey rootKey)
{
// Check the arguments.
if (null == slice) throw new ArgumentNullException("slice");
// Set the slice.
this.slice = slice;
// Set the slice event handler.
this.slice.Changed += this.OnSliceChanged;
// Open or create the subkey for the current slice.
if (null == (this.key = rootKey.OpenSubKey(this.slice.Id.Value.ToString(), RegistryKeyPermissionCheck.ReadWriteSubTree)))
{
// If the key does not exist, create the key.
this.key = rootKey.CreateSubKey(this.slice.Id.Value.ToString());
}
// Check the commands directory exists.
if (!Directory.Exists(CrawlerConfig.Static.PlanetLabSlicesFolder))
{
// If the directory does not exist, create it.
Directory.CreateDirectory(CrawlerConfig.Static.PlanetLabSlicesFolder);
}
// Create the slice log.
this.log = new Logger(CrawlerConfig.Static.PlanetLabSlicesLogFileName.FormatWith(this.slice.Id, "{0}", "{1}", "{2}"));
// Create the slice commands configuration.
this.commands = new PlConfigSliceCommands(this.key, this.slice.Id.Value);
}
示例8: CreateKey
/// <summary>
///
/// </summary>
/// <param name="root"></param>
/// <param name="subKey"></param>
internal static void CreateKey(RegistryKey root, string subKey)
{
RegistryKey rk = null;
try {
rk = root.CreateSubKey( subKey );
if ( rk != null ) {
Log.AppendString( logfile, "Created key: " + rk.ToString() + Environment.NewLine );
Display.UpdateStatus( "Created: " + root.ToString() + "\\..." + subKey.Substring( subKey.LastIndexOf( '\\' ) ) + "\\*" );
}
}
catch ( Exception ex ) {
// Record exceptions in the log file
Log.AppendException( logfile, ex );
}
finally {
// Finally, cleanup and prepare variables for garbage collection
if ( rk != null ) {
rk.Close();
rk = null;
}
subKey = null;
}
}
示例9: TestInitialize
public void TestInitialize()
{
var counter = Interlocked.Increment(ref s_keyCount);
_testKey += counter.ToString();
_rk1 = Microsoft.Win32.Registry.CurrentUser;
if (_rk1.OpenSubKey(_testKey) != null)
_rk1.DeleteSubKeyTree(_testKey);
if (_rk1.GetValue(_testKey) != null)
_rk1.DeleteValue(_testKey);
//created the test key. if that failed it will cause many of the test scenarios below fail.
try
{
_rk1 = Microsoft.Win32.Registry.CurrentUser;
_rk2 = _rk1.CreateSubKey(_testKey);
if (_rk2 == null)
{
Assert.False(true, "ERROR: Could not create test subkey, this will fail a couple of scenarios below.");
}
else
_keyString = _rk2.ToString();
}
catch (Exception e)
{
Assert.False(true, "ERROR: unexpected exception, " + e.ToString());
}
}
示例10: SetString
public void SetString(RegistryKey hive, string key, string valueName, string value)
{
using (var subKey = hive.CreateSubKey(key))
{
subKey.SetValue(valueName, value);
}
}
示例11: Guardar
public static void Guardar(RegistryKey raiz, String nombreClave, String nombreValor, Object valor)
{
RegistryKey clave;
clave = raiz.OpenSubKey(nombreClave, true);
if (clave == null) clave = raiz.CreateSubKey(nombreClave);
clave.SetValue(nombreValor, valor);
}
示例12: SetQWord
public void SetQWord(RegistryKey hive, string key, string valueName, long value)
{
using (var subKey = hive.CreateSubKey(key))
{
subKey.SetValue(valueName, value, RegistryValueKind.QWord);
}
}
示例13: Configuration
public Configuration()
{
OperatingSystem os = Environment.OSVersion;
Console.WriteLine ("OS platform: " + os.Platform);
this.platform = os.Platform.ToString ();
if (this.platform.StartsWith ("Win")) {
RegistryKey CurrentUserKey = Microsoft.Win32.Registry.CurrentUser;
string OurAppKeyStr = @"SOFTWARE\moNotationalVelocity";
OurAppRootKey = CurrentUserKey.CreateSubKey (OurAppKeyStr);
ConfigKey = OurAppRootKey.CreateSubKey ("config");
this.notesDirPath = ConfigKey.GetValue ("notesDirPath") as string;
if (this.notesDirPath == null) {
Console.WriteLine ("No configuration");
this.notesDirPath = defaulNotesDirtPath;
ConfigKey.SetValue ("notesDirPath", this.notesDirPath, RegistryValueKind.String);
}
ConfigKey.Flush ();
} else {
this.notesDirPath = defaulNotesDirtPath;
}
}
示例14: GetKey
protected RegistryKey GetKey(RegistryKey root, string subkey, bool writeable)
{
RegistryKey key = root.OpenSubKey(subkey, writeable);
if (key == null && writeable)
key = root.CreateSubKey(subkey);
return key;
}
示例15: SetRegistryValue
public static bool SetRegistryValue(RegistryKey RootKey, string szSubKey, string szItem, string value)
{
bool bIsSuccessful = false;
try
{
RegistryKey registryKey = RootKey.OpenSubKey(szSubKey, true);
if (registryKey == null)
{
registryKey = RootKey.CreateSubKey(szSubKey);
}
if (registryKey != null)
{
using (registryKey)
{
registryKey.SetValue(szItem, value);
bIsSuccessful = true;
}
}
}
catch (UnauthorizedAccessException)
{
return bIsSuccessful;
}
return bIsSuccessful;
}