2012-03-22 16 views
0

プログラムによるBIOSの時刻設定の変更方法は?このコードは、C#Window Formsアプリケーションに組み込まれ、BIOS設定が常にUTC時間になるようにします。 Win32_UTCTimeを使用してWMIに解決策を見つけることには成功しましたが、失敗しました。プログラムによるBIOSの時刻設定の変更方法は?

答えて

0

BIOSクロックを変更/操作する前にread this article。これは、Windowsがローカル時刻を追跡する時計に依存している理由を説明します。だからあなたはそれを変えないようにしたいかもしれない。あなたは、プログラムの任意の通常の手段で... BIOSの時間を変更することはできません実際の変化see this example from on PInvoke.NET

class Class1 
{ 
    /// <summary> This structure represents a date and time. </summary> 
    public struct SYSTEMTIME 
    { public ushort wYear,wMonth,wDayOfWeek,wDay, 
      wHour,wMinute,wSecond,wMilliseconds; 
    } 

    /// <summary> 
    /// This function retrieves the current system date 
    /// and time expressed in Coordinated Universal Time (UTC). 
    /// </summary> 
    /// <param name="lpSystemTime">[out] Pointer to a SYSTEMTIME structure to 
    /// receive the current system date and time.</param> 
    [DllImport("kernel32.dll")] 
    public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime); 

    /// <summary> 
    /// This function sets the current system date 
    /// and time expressed in Coordinated Universal Time (UTC). 
    /// </summary> 
    /// <param name="lpSystemTime">[in] Pointer to a SYSTEMTIME structure that 
    /// contains the current system date and time.</param> 
    [DllImport("kernel32.dll")] 
    public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime); 

    static void Main() 
    { Console.WriteLine(DateTime.Now.ToString()); 
     SYSTEMTIME st = new SYSTEMTIME(); 
     GetSystemTime(ref st); 
     Console.WriteLine("Adding 1 hour..."); 
     st.wHour = (ushort)(st.wHour + 1 % 24); 
     if (SetSystemTime(ref st) == 0) 
      Console.WriteLine("FAILURE: SetSystemTime failed"); 
     Console.WriteLine(DateTime.Now.ToString()); 
     Console.WriteLine("Setting time back..."); 
     st.wHour = (ushort)(st.wHour - 1 % 24); 
     SetSystemTime(ref st); 
     Console.WriteLine(DateTime.Now.ToString()); 
     Console.WriteLine("Press Enter to exit"); 
     Console.Read(); 
    } 
} 
+0

私の知る限り、このアプローチはシステム時間だけを変更しますが、BIOS時間は変更されません。私が間違っている? – FMuk

+0

Windowsの時刻を設定すると、マシンのBIOS時刻が変更されます。 –

+0

あなたが参照しているソースによると、ハードウェアリアルタイムクロック(BIOSヘルプで時刻を設定するときに「BIOS時刻」と命名されました)とOSに示されたシフトを持つRTCに基づくシステム(Windows)時刻です(たとえばタイムゾーンなど)。 Windows APIは、システム(OS)の時刻のみを変更します。 (私が何か間違って理解できれば申し訳ありません) – FMuk

0

を行うには

BIOSは、オペレーティングシステムとは独立したEEPROMに格納されています。それと対話する唯一の方法は、ハードウェアに直接書き込む直接的なプログラムによるものです。さまざまなAPIはこれを行う方法を提供しません。

関連する問題