【发布时间】:2015-02-18 17:42:15
【问题描述】:
我正在尝试使用下面的代码示例更改 Windows 8 系统日期时间。
Private Structure SYSTEMTIME
Public year As Short
Public month As Short
Public dayOfWeek As Short
Public day As Short
Public hour As Short
Public minute As Short
Public second As Short
Public milliseconds As Short
End Structure
<DllImport("Kernel32.dll")> Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As Boolean
End Function
Private Sub ChangeDate
Dim st As SYSTEMTIME
Dim NewDate As Date = "28-April-1978 22:30:00"
st.year = NewDate .Year
st.month = NewDate.Month
st.dayOfWeek = NewDate.DayOfWeek
st.day = NewDate.Day
st.hour = NewDate.Hour
st.minute = NewDate.Minute
st.second = NewDate.Second
st.milliseconds = NewDate.Millisecond
'Set the new time...
SetLocalTime(st)
End Sub
当我打印 SetLocalTime 的结果时,它返回 false 并且系统的日期时间没有改变。我也尝试过 SetSystemTime 函数,但它返回 0 并且也没有改变任何东西。我在 Windows 上使用管理员帐户。
我应该修改什么才能使它工作?
【问题讨论】: