Option Explicit
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege"
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(1) As LUID_AND_ATTRIBUTES
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Long
End Type
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByVal PreviousState As Long, ByVal ReturnLength As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
'Private Sub Button1_Released()
Private Sub settime()
Dim hToken As Long
Dim TokenPrivilegeLuid As LUID
Dim TokenPrivilege As TOKEN_PRIVILEGES
Dim dwTime As SYSTEMTIME
Dim temp1 As TagGroup '添加变量组,向组内添加变量
Set temp1 = CreateTagGroup(Me.AreaName)
temp1.Add ("time_year") '所添加的变量在SE 中 HMI Tag中建立并关联PLC中wallclocktime
temp1.Add ("time_month")
temp1.Add ("time_day")
temp1.Add ("time_hour")
temp1.Add ("time_minute")
temp1.Add ("time_second")
temp1.Add ("time_milliseconds")
'检查SE_SYSTEMTIME_NAME权限,该权限必须为Enable
OpenProcessToken GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken
LookupPrivilegeValue vbNullString, SE_SYSTEMTIME_NAME, TokenPrivilegeLuid
With TokenPrivilege
.PrivilegeCount = 1
.Privileges(0).pLuid = TokenPrivilegeLuid
.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
End With
AdjustTokenPrivileges hToken, False, TokenPrivilege, LenB(TokenPrivilege), 0, 0
CloseHandle hToken
With dwTime
.wYear = temp1.Item("time_year").Value
.wMonth = temp1.Item("time_month").Value
.wDay = temp1.Item("time_day").Value
.wHour = temp1.Item("time_hour").Value
.wMinute = temp1.Item("time_minute").Value
.wSecond = temp1.Item("time_second").Value
.wMilliseconds = temp1.Item("time_milliseconds").Value
End With
If SetLocalTime(dwTime) = 0 Then
MsgBox "修改时间失败"
End If
End Sub
Private Sub Display_Load()
Call settime '加载画面时调用自定义settime
End Sub
关于论坛发帖上传资料附件的操作说明
http://bbs.gongkong.com/d/201903/786833_1.shtml
楼主可以把您的资料以附件形式上传的,上面是论坛上传附件的操作说明,供你参考。