本文整理汇总了C#中Microsoft.Win32.RegistryKey.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.SetValue方法的具体用法?C# RegistryKey.SetValue怎么用?C# RegistryKey.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SystemInformation
internal SystemInformation(RegistryKey key)
{
bool loaded = false;
LastStartupDateTime = DateTime.Now;
try
{
if (key.GetValue(KeyInstallation) != null)
{
InstallationDateTime = DateTime.ParseExact(
(string)key.GetValue(KeyInstallation), "O",
CultureInfo.InvariantCulture
);
string lastReportDate = (string)key.GetValue(KeyLastReport);
if (lastReportDate != null)
{
LastReportDateTime = DateTime.ParseExact(
lastReportDate, "O", CultureInfo.InvariantCulture
);
}
#if CACHE_SYSTEM_INFORMATION
OperatingSystem = (string)key.GetValue(KeyOperatingSystem);
OperationSystemVersion = (string)key.GetValue(KeyOperationSystemVersion);
Cpu = (string)key.GetValue(KeyCpu);
CpuInformation = (string)key.GetValue(KeyCpuInformation);
#endif
loaded = true;
}
}
catch
{
// If we were unable to load the settings, initialize new settings.
}
if (!loaded)
{
Detect();
key.SetValue(KeyInstallation, InstallationDateTime.ToString("O"));
if (key.GetValue(KeyLastReport) != null)
key.DeleteValue(KeyLastReport);
#if CACHE_SYSTEM_INFORMATION
key.SetValue(KeyOperatingSystem, OperatingSystem);
key.SetValue(KeyOperationSystemVersion, OperationSystemVersion);
key.SetValue(KeyCpu, Cpu);
key.SetValue(KeyCpuInformation, CpuInformation);
#endif
}
#if !CACHE_SYSTEM_INFORMATION
DetectSystemInformation();
#endif
}
示例2: AddFreddyToRegistry
private static void AddFreddyToRegistry()
{
_key = Registry.CurrentUser.CreateSubKey("SpringIocQuickStartVariableSources");
_key.SetValue("freddy_name", "Freddy Rumsen");
_key.SetValue("freddy_age", 44, RegistryValueKind.DWord);
_key.Flush();
}
示例3: checklogintime
public void checklogintime()
{
mainwindow.CurrentStartTime = DateTime.Now.Date;
rsg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Sakuya\\" + mainwindow.name);
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Sakuya\\" + mainwindow.name, true);
Thread.Sleep(50);
if (mainwindow.CurrentStartTime == mainwindow.LastStartTime)//如果是今天第N次打开
{
mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays;
}
else if ((mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays == 1)//如果就在第二天
{
mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays;
rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime));
}
else//不是在第二天
{
if ((mainwindow.CurrentStartTime - mainwindow.LastStartTime).TotalDays == 1)//如果是在上一次记录的后面一天
{
mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays;
rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime));
}
else//如果不是连续打开的
{
rsg.SetValue("inStartTime", Convert.ToString(mainwindow.CurrentStartTime));
rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime));
mainwindow.inStartTime = mainwindow.CurrentStartTime;
}
}
}
示例4: AddFreddyToRegistry
private static void AddFreddyToRegistry()
{
_key = Registry.CurrentUser.CreateSubKey(_subkey);
_key.SetValue("freddy_name", "Freddy Rumsen");
_key.SetValue("freddy_age", 44, RegistryValueKind.DWord);
_key.Flush();
}
示例5: 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);
}
示例6: SetUp
public void SetUp()
{
key = Registry.CurrentUser.CreateSubKey("RegistryVariableSourceTests");
key.SetValue("name", "Aleks Seovic");
key.SetValue("computer_name", "%COMPUTERNAME% is the name of my computer", RegistryValueKind.ExpandString);
key.SetValue("age", 32, RegistryValueKind.DWord);
key.SetValue("family", new string[] {"Marija", "Ana", "Nadja"});
key.SetValue("bday", new byte[] {24, 8, 74});
key.Flush();
}
示例7: Save
public void Save(RegistryKey regkey)
{
Trim();
if (history.Count == 0)
return;
regkey.SetValue(key, history[0]);
for (int i = 1; i < history.Count; i++)
regkey.SetValue(key + i.ToString(CultureInfo.InvariantCulture), history[i]);
}
示例8: button1_Click
private void button1_Click(object sender, EventArgs e)
{
Host = textHost.Text;
Login = textLogin.Text;
Password = textPass.Text;
regKey = Registry.CurrentUser;
regKey = regKey.CreateSubKey("Software\\TickNet\\DBServer");
regKey.SetValue("DB_Server",textHost.Text);
regKey.SetValue("DB_Login",textLogin.Text);
regKey.SetValue("DB_Pass",textPass.Text);
this.DialogResult = DialogResult.OK;
}
示例9: IEHeaderFooterSettings
/// <summary>
/// Page setup with the specifed header and footer.
/// </summary>
/// <param name="header"></param>
/// <param name="footer"></param>
public IEHeaderFooterSettings(string header, string footer)
{
_iePageSetupKey = Registry.CurrentUser.OpenSubKey(_iePageSetupKeyPath, true);
_header = header;
_footer = footer;
if (_iePageSetupKey != null)
{
_oldHeader = (string)_iePageSetupKey.GetValue("header");
_oldFooter = (string)_iePageSetupKey.GetValue("footer");
_iePageSetupKey.SetValue("header", _header);
_iePageSetupKey.SetValue("footer", _footer);
}
}
示例10: CheckValidOrCreateRegValue
/// <summary>
/// Checks if a stringValue is available. If it is not, it creates it
/// </summary>
/// <param name="subKey"></param>
/// <param name="stringValue"></param>
/// <param name="defaultStringValue"></param>
/// <returns></returns>
private static bool CheckValidOrCreateRegValue(RegistryKey subKey, string propertyName, string defaultStringValue)
{
try
{
if(subKey.GetValue(propertyName) == null)
{
if(defaultStringValue == null)
{
return true;
}
//create the stringvlaue
subKey.SetValue(propertyName, defaultStringValue);
return true;
}
else
{
return true;
}
}
catch(Exception ex)
{
log.Error(ex);
return false;
}
}
示例11: 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 { }
}
示例12: 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;
}
}
示例13: registerProgram
public bool registerProgram(string appName, string pathToExe)
{
try
{
if (!isProgramRegistered(appName))
{
startupKey = Registry.CurrentUser.OpenSubKey(runKey);
if (startupKey.GetValue(appName) == null)
{
startupKey.Close();
startupKey = Registry.CurrentUser.OpenSubKey(runKey, true);
startupKey.SetValue(appName, pathToExe);
}
}
}
catch (Exception)
{
return false;
}
finally
{
startupKey.Close();
}
return true;
}
示例14: RenameFontName
public static void RenameFontName(RegistryKey key, string original, string target, string value)
{
// TODO: Use transection.
key.SetValue(target, value);
key.DeleteValue(original);
}
示例15: IISFix
/// <summary>
/// This fixes my mistake for naming IIS process "wp3.exe" and not "w3wp.exe" like it should be.
/// </summary>
/// <param name="key"></param>
/// <param name="descriptorIndex"></param>
internal static void IISFix(RegistryKey key, int descriptorIndex)
{
try
{
// get the name.
var name = key.GetStringValue(ATASettings.Keys.AttachDescriptorName, descriptorIndex);
var processGroup = key.GetStringValue(ATASettings.Keys.AttachDescriptorProcessNames, descriptorIndex);
var allProcesses = ((string) key.GetValue(processGroup)).Split(new[] {ATAConstants.ProcessNamesSeparator[0]}, StringSplitOptions.RemoveEmptyEntries);
const string badProcessName = "wp3.exe";
// does it have the fouled-up process name?
var hasWp3 = allProcesses.Any(s => string.Compare(s, badProcessName, StringComparison.OrdinalIgnoreCase) == 0);
// if it is iis, and it has the wrong process, fix that shit.
if (string.Compare(name, "iis", StringComparison.OrdinalIgnoreCase) != 0 || !hasWp3)
{
return;
}
var newList = allProcesses.Where(s => string.Compare(s, badProcessName, StringComparison.OrdinalIgnoreCase) != 0).Concat(new[] {ATAConstants.ProcessNames.IISWorkerProcessName});
key.SetValue(processGroup, string.Join(ATAConstants.ProcessNamesSeparator, newList));
}
catch (Exception)
{
// if we dont have access to write, there is a problem.
}
}