以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]能否调整电脑系统的时间 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194442) |
-- 作者:fczhaobo -- 发布时间:2024/12/10 18:37:00 -- [求助]能否调整电脑系统的时间 个别客户端的电脑系统日期和时间不准,能否进行调整,如何处理? |
-- 作者:有点蓝 -- 发布时间:2024/12/10 19:42:00 -- https://www.baidu.com/s?wd=vb.net%20%E6%9B%B4%E6%94%B9%E7%B3%BB%E7%BB%9F%E6%97%B6%E9%97%B4 |
-- 作者:fczhaobo -- 发布时间:2024/12/10 20:02:00 -- 蓝老师好,实在转不进来,请详解,谢谢 |
-- 作者:有点蓝 -- 发布时间:2024/12/10 20:12:00 -- 全局代码 Public Class Form1 < DllImport("kernel32.dll", SetLastError:=True) > Private Shared Function SetSystemTime(ByRef systime As SYSTEMTIME) As Boolean End Function < StructLayout(LayoutKind.Sequential) > Public 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 \' 更改系统时间的函数 Public Sub ChangeSystemTime(newDateTime As DateTime) Dim sysTime As New SYSTEMTIME() sysTime.year = CType(newDateTime.Year, Short) sysTime.month = CType(newDateTime.Month, Short) sysTime.day = CType(newDateTime.Day, Short) sysTime.hour = CType(newDateTime.Hour, Short) sysTime.minute = CType(newDateTime.Minute, Short) sysTime.second = CType(newDateTime.Second, Short) sysTime.milliseconds = CType(newDateTime.Millisecond, Short) If SetSystemTime(sysTime) Then \' 成功更改时间 MessageBox.Show("系统时间已更改。") Else \' 更改失败,可以通过Marshal.GetLastWin32Error()获取错误代码 MessageBox.Show("更改系统时间失败,错误代码:" & Marshal.GetLastWin32Error().ToString()) End If End Sub End Class 调用 Dim a As New Form1() a.ChangeSystemTime(New Date(2024, 12, 9, 12, 0, 0)) |