I can't get SetSystemTime to work in Windows Vista using C# with Interop (P/Invoke)

后端 未结 2 1197
孤城傲影
孤城傲影 2021-01-17 05:52

I\'m having a hard time getting SetSystemTime working in my C# code. SetSystemtime is a kernel32.dll function. I\'m using P/invoke (interop) to call it. SetSystemtime retu

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 05:59

    You can't just add 3000 to the seconds field. You need to specify a number of seconds between 0 and 60. You need to adjust the seconds, minutes, hours, etc fields so that they are all within a valid range.

    Edit The simplest way would actually be to call SystemTimeToFileTime then add numSeconds * 10000 to the value it gives back, and then call FileTimeToSystemTime to convert back to a SystemTime.

提交回复
热议问题