0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Windowsでローカルタイムゾーンの夏時間設定の確認方法

Last updated at Posted at 2021-06-21

Windowsでローカルタイムゾーンの夏時間設定の確認方法

「夏時間に合わせて自動調整する」がオンになっているか否かを確認したい場合、
.NET Frameworkが提供するRegistryKeyクラス(Microsoft.Win32名前空間)を利用し、

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

のキー[DynamicDaylightTimeDisabled]の値を参照します。

Registry.GetValue メソッド
このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

キーと値を変えてやれば、これ以外にもレジストの値を取得することが可能です。
(型は、呼び出すレジストリの値の型に合わせてやる必要があります。)

GetRegistryKey.cs
using System;
using Microsoft.Win32;

namespace GetRegistryKey
{
    class Program
    {
        static void Main(string[] args)
		{
			// 操作するレジストリ・キーの名前
			string rKeyName = @"SYSTEM\CurrentControlSet\Control\TimeZoneInformation";
			// 取得処理を行う対象となるレジストリの値の名前
			string rGetValueName = "DynamicDaylightTimeDisabled";

			// レジストリの取得
			try
			{
				// レジストリ・キーのパスを指定してレジストリを開く
				RegistryKey rKey = Registry.LocalMachine.OpenSubKey(rKeyName);

				// レジストリの値を取得
				Int32 location = (Int32)rKey.GetValue(rGetValueName);

				// 開いたレジストリを閉じる
				rKey.Close();

				// コンソールに取得したレジストリの値を表示
				Console.WriteLine("夏時間に合わせて自動的に調整しない:" + location);
				Console.ReadLine();
			}
			catch (NullReferenceException)
			{
				// レジストリ・キーまたは値が存在しない
				Console.WriteLine("レジストリ[" + rKeyName	+ "]の[" + rGetValueName + "]がありません!");
			}
		}
	}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?