Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class OsVersion
- {
- /// <summary>
- /// 太平洋標準時
- /// </summary>
- private static readonly TimeSpan PST = new TimeSpan(-8, 0, 0);
- /// <summary>
- /// Windows NT 5.1(Windows XP)のサポート終了日
- /// </summary>
- private static readonly DateTimeOffset WindowsNT_5_1_End = new DateTimeOffset(2014, 4, 8, 0, 0, 0, PST);
- /// <summary>
- /// Windows NT 5.2(Windows Server 2003, Windows XP x64 Edition)のサポート終了日
- /// </summary>
- private static readonly DateTimeOffset WindowsNT_5_2_End = new DateTimeOffset(2015, 7, 14, 0, 0, 0, PST);
- private delegate void KillOldVersionDelegate();
- private static KillOldVersionDelegate Delegate;
- private static IAsyncResult Result;
- private static Boolean TerminateThread;
- private static readonly String SystemDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);
- private static readonly FileVersionInfo KernelVersion = FileVersionInfo.GetVersionInfo(SystemDirectory + @"\NTOSKRNL.EXE");
- private static readonly FileVersionInfo HardwareAbstractLayerVersion = FileVersionInfo.GetVersionInfo(SystemDirectory + @"\HAL.DLL");
- public static void KillOldVersion()
- {
- Delegate = new KillOldVersionDelegate(KillOldVersionThread);
- TerminateThread = false;
- Result = Delegate.BeginInvoke(null, null);
- }
- public static void Finish()
- {
- TerminateThread = true;
- Delegate.EndInvoke(Result);
- }
- private static void KillOldVersionThread()
- {
- while(!TerminateThread)
- {
- if(!IsOperatingSystemSupportingNow())
- {
- MessageBox.Show("現在実行中のオペレーティング システムはサポート期間を過ぎているため、動作を継続できません。", "致命的なエラー", MessageBoxButton.OK, MessageBoxImage.Hand);
- // 終了処理
- throw new Exception("Your operating system is not supported.");
- }
- Thread.Sleep(1000);
- }
- }
- private static Boolean IsOperatingSystemSupportingNow()
- {
- var Now = new DateTimeOffset(DateTime.Now);
- Int32 RequiredMajor, RequiredMinor, CurrentMajor, CurrentMinor;
- if(Now >= WindowsNT_5_2_End)
- {
- RequiredMajor = 6;
- RequiredMinor = 0;
- }
- else if(Now >= WindowsNT_5_1_End)
- {
- RequiredMajor = 5;
- RequiredMinor = 2;
- }
- else
- {
- RequiredMajor = 5;
- RequiredMinor = 1;
- }
- CurrentMajor = Math.Min(KernelVersion.ProductMajorPart, HardwareAbstractLayerVersion.ProductMajorPart);
- CurrentMinor = Math.Min(KernelVersion.ProductMinorPart, HardwareAbstractLayerVersion.ProductMinorPart);
- if(CurrentMajor < RequiredMajor)
- {
- return false;
- }
- if(CurrentMajor == RequiredMajor)
- {
- if(CurrentMinor < RequiredMinor)
- {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement