Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 119,689 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 2,078 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!


Submitted By: jacobjordan
Actions:
Rating:
Views: 173

Language: VB.NET

Last Modified: July 5, 2008
Instructions: Use the SetComputerTime() method. If you really want to do it the hard way, you could use the SetLocalTime() base method.

Snippet


  1.     ''' <summary>
  2.     ''' Sets the computers local time
  3.     ''' </summary>
  4.     ''' <param name="TimeToSet">The time to set the computers clock to</param>
  5.     Public Sub SetComputerTime(ByVal TimeToSet As Date)
  6.         Dim systime As SYSTEMTIME = New SYSTEMTIME
  7.         systime.Day = TimeToSet.Day
  8.         systime.Year = TimeToSet.Year
  9.         systime.Month = TimeToSet.Month
  10.         systime.DayOfWeek = TimeToSet.DayOfWeek
  11.         systime.Hour = TimeToSet.Hour
  12.         systime.Second = TimeToSet.Second
  13.         systime.Minute = TimeToSet.Minute
  14.         systime.Milliseconds = TimeToSet.Millisecond
  15.         SetLocalTime(systime)
  16.     End Sub
  17.     Declare Function SetLocalTime Lib "kernel32.dll" (ByRef time As SYSTEMTIME) As Boolean
  18.     Structure SYSTEMTIME
  19.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Year As Short
  20.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Month As Short
  21.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public DayOfWeek As Short
  22.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Day As Short
  23.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Hour As Short
  24.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Minute As Short
  25.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Second As Short
  26.         <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.U2)> Public Milliseconds As Short
  27.     End Structure

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month