Makine süresini C# olarak ayarlamanın en iyi yolu nedir? Ben çerçeve içine pişmiş bir şey yok oldukça eminimMakine zamanını ayarlayın C#
5
A
cevap
7
Muhtemelen, bunun için Win32 API kullanmak gerekir:
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME {
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetSystemTime(ref SYSTEMTIME theDateTime);
PInvoke.net de daha ayrıntılı bir örnek var, kod biraz kalabalık şehir ama okumak ve anlamak oldukça sade olan bir basit alıntı şudur:
SYSTEMTIME st = new SYSTEMTIME();
GetSystemTime(ref st);
// Adds one hour to the time that was retrieved from GetSystemTime
st.wHour = (ushort)(st.wHour + 1 % 24);
var result = SetSystemTime(ref st);
if (result == false)
{
// Something went wrong
}
else
{
// The time will now be 1hr later than it was previously
}
ilgili spesifik Win32 API en SetSystemTime, GetSystemTime ve SYSTEMTIME yapıyı vardır.
1
Microsoft.VisualBasic.DateAndTime.TimeOfDay = dateTime; Eğer bana her konuda eğer
dup bildirin proje
Microsoft.VisualBasic bir başvuru ekleyin? http://stackoverflow.com/questions/204936/set-time-programmatically-using-c – kenny
@kenny: Sanırım, uzak makinelerden bahsediyorsunuz. –
Bu soru tam olarak yinelenmez, çünkü bu soru uzak bir makinede nasıl yapılacağını soruyor. –