Home > Net >  Under the win10 system, the following code cannot modify system time, please help a look
Under the win10 system, the following code cannot modify system time, please help a look

Time:10-04

Imports System. The Runtime. InteropServices
Imports System. Text

Public Class SetSystemDateTime

Public Structure SystemTime
Public wYear As UShort
Public wMonth As UShort
Public wDay As UShort
Public wHour As UShort
Public wMinute As UShort
Public wSecond As UShort
End Structure


_
Public Shared Function SetLocalTime (ByRef sysTime As SystemTime) As Boolean
End the Function

The Public Function SetLocalTimeByStr (ByVal timestr As String) As Boolean
Dim flag As Boolean=False
Dim sysTime As New SystemTime ()
Dim dt As DateTime
Try
'the dt=the Convert. ToDateTime (timestr)
Dt="2020-10-03 08:10:10"
SysTime. WYear=the Convert. ToUInt16 (dt) Year)
SysTime. WMonth=the Convert. ToUInt16 (dt) Month)
SysTime. WDay=the Convert. ToUInt16 (dt) Day)
SysTime. WHour=the Convert. ToUInt16 (dt) Hour)
SysTime. WMinute=the Convert. ToUInt16 (dt) Minute)
SysTime. WSecond=the Convert. ToUInt16 (dt. Second)
Flag=SetSystemDateTime. SetLocalTime (sysTime)
Catch the ex As Exception
MsgBox (timestr & "" & ex. Message & Now, 0)
End the Try
If Not flag Then MsgBox (dt & "" & sysTime. WDay &" "& flag &" "& Now, 0)
Return flag
End the Function

The End of the Class
  • Related