Re: Change system date
From: Crouchie1998 (Crouchie1998_at_discussions.microsoft.com)
Date: 02/15/05
- Next message: Crouchie1998: "RE: disabling error reporting"
- Previous message: Lloyd Sheen: "Re: No more debugging"
- In reply to: Herfried K. Wagner [MVP]: "Re: Change system date"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 19:13:01 -0800
Here's a VB.NET solution to change system time:
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Public Structure SYSTEMTIME
Public wYear As Short
Public wMonth As Short
Public wDayOfWeek As Short
Public wDay As Short
Public wHour As Short
Public wMinute As Short
Public wSecond As Short
Public wMilliseconds As Short
End Structure
Private Declare Function SetSystemTime Lib "kernel32" (ByRef
lpSystemTime As SYSTEMTIME) As Integer
Private Declare Sub GetSystemTime Lib "kernel32" Alias "GetSystemTime"
(ByRef lpSystemTime As SYSTEMTIME)
Usage (SetSystemTime):
Dim st As SYSTEMTIME
With st
.wDay = 1
.wMonth = 1
.wYear = 1981
.wMinute = 1
.wHour = 1
.wSecond = 0
End With
If SetSystemTime(st) = 1 Then
MessageBox.Show("System Time Changed")
Else
MessageBox.Show(Marshal.GetLastWin32Error.ToString)
End If
Usage (GetSystemTime):
Dim sysTime As SYSTEMTIME
GetSystemTime(sysTime)
MessageBox.Show(sysTime.wHour.ToString())
Obviously, I am running under administration rights & you need to take this
into account if you are just a user.
I hope this helps
- Next message: Crouchie1998: "RE: disabling error reporting"
- Previous message: Lloyd Sheen: "Re: No more debugging"
- In reply to: Herfried K. Wagner [MVP]: "Re: Change system date"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|