1、GetSystemTime和SetSystemTime分别用于返回和设置系统时间。
2、ShellExecute是执行外部程序。
3、Sleep用于延迟时间,暂停程序的执行。- Option Explicit
- Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
- Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
- 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 Integer
- End Type
- Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
- Private Const SW_SHOWNORMAL = 1
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Private Sub Form_Load()
- ' 返回系统时间
- Dim SysTime As SYSTEMTIME
- GetSystemTime SysTime
- Dim y As Integer
- Dim m As Integer
- Dim d As Integer
- y = SysTime.wYear
- m = SysTime.wMonth
- d = SysTime.wDay
-
- ' 设置系统新时间
- SysTime.wYear = 2004
- SysTime.wMonth = 1
- SysTime.wDay = 1
- SetSystemTime SysTime
-
- ' 执行外部程序
- ShellExecute 0, vbNullString, "calc.exe", vbNullString, vbNullString, SW_SHOWNORMAL
-
- ' 延迟时间
- Sleep 5000
-
- ' 还原系统时间
- SysTime.wYear = y
- SysTime.wMonth = m
- SysTime.wDay = d
- SetSystemTime SysTime
- End Sub
|