का उपयोग कर रहा का उपयोग कर अपने सिस्टम समय अद्यतन करने के लिए कोशिश कर रहा हूँ निम्नलिखित प्रणाली की तारीख और/या समय अद्यतन करने के लिए कैसे:नेट
[StructLayout(LayoutKind.Sequential)]
private struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
private extern static void Win32GetSystemTime(ref SYSTEMTIME lpSystemTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
private extern static bool Win32SetSystemTime(ref SYSTEMTIME lpSystemTime);
public void SetTime()
{
TimeSystem correctTime = new TimeSystem();
DateTime sysTime = correctTime.GetSystemTime();
// Call the native GetSystemTime method
// with the defined structure.
SYSTEMTIME systime = new SYSTEMTIME();
Win32GetSystemTime(ref systime);
// Set the system clock ahead one hour.
systime.wYear = (ushort)sysTime.Year;
systime.wMonth = (ushort)sysTime.Month;
systime.wDayOfWeek = (ushort)sysTime.DayOfWeek;
systime.wDay = (ushort)sysTime.Day;
systime.wHour = (ushort)sysTime.Hour;
systime.wMinute = (ushort)sysTime.Minute;
systime.wSecond = (ushort)sysTime.Second;
systime.wMilliseconds = (ushort)sysTime.Millisecond;
Win32SetSystemTime(ref systime);
}
जब मैं सब कुछ अच्छा लग रहा है डिबग और सभी मूल्यों सही हैं लेकिन जब यह सिस्टम के वास्तविक समय (प्रदर्शन समय) के Win32SetSystemTime (रेफ सिस्टिम) को कॉल करता है और बदलता रहता है। अजीब बात यह है कि जब मैं Win32GetSystemTime (रेफ सिस्टिम) कहता हूं तो यह मुझे नया अपडेट किया गया समय देता है। क्या कोई मुझे इस पर कुछ मदद दे सकता है?
के रूप में मैं देखता हूँ, TimeSystem आधार प्रणाली कक्षा से गैर है, तो आप यह सुनिश्चित करें कि TimeSystem में परिवर्तन नहीं करते पहर? Win32SetSystemTime (रेफ सिस्टिम) पर टिप्पणी करने का प्रयास करें; लाइन – Avram