Change system date

  • Thread starter Thread starter Richard
  • Start date Start date
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Asset Management - PC Birth Date 11
Excel Vba to change displayed year automatically. 14
MX Linux 21 5
Excel Colour code dates 1
Excel Message box with days of month & date. 1
Excel Excel Show Countdown Date 7
Excel Excel due and overdue date colours 2
Windows 10 Microsoft updates HELP 5

Back
Top