private string GetRegistData(string name) { string registData; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("Software", true); RegistryKey aimdir = software.OpenSubKey("NewTimeyear", true); registData = aimdir.GetValue(name).ToString(); return registData; } private void WTRegedit(string name, string tovalue) { RegistryKey hklm = Registry.CurrentUser; RegistryKey software = hklm.OpenSubKey("Software", true); RegistryKey aimdir = software.CreateSubKey("NewTimeyear"); aimdir.SetValue(name, tovalue); } private bool IsRegeditExit(string name) { bool _exit = false; string[] subkeyNames; RegistryKey hkml = Registry.CurrentUser; RegistryKey software = hkml.OpenSubKey("Software", true); RegistryKey aimdir = software.OpenSubKey("NewTimeyear", true); if (aimdir == null) { return false; } subkeyNames = aimdir.GetSubKeyNames(); foreach (string keyName in subkeyNames) { if (keyName == name) { _exit = true; return _exit; } } return _exit; }
NowTime = DateTime.Now.ToLocalTime(); Timeyear = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd");
if (!IsRegeditExit("TimeYear")) { WTRegedit("TimeYear", Timeyear); } RegTime = GetRegistData("TimeYear");
DateTime DateReg = Convert.ToDateTime(RegTime); DateTime MaxDate = Convert.ToDateTime(MaxTime); DateTime MinDate = Convert.ToDateTime(MinTime); if (!((NowTime.CompareTo(MinDate) >= 0 && NowTime.CompareTo(MaxDate) <= 0) && (DateReg.CompareTo(MinDate) >= 0 && DateReg.CompareTo(MaxDate) <= 0))) { Application.Quit(); }