Solved

change system clock through asp.net

Posted on 2009-07-07
7
322 Views
Last Modified: 2013-11-07
Hi there,
I need to programmatically change the system clock .
I am using vb.net.

Thanks
0
Comment
Question by:bkourouma
  • 4
7 Comments
 
LVL 4

Expert Comment

by:JimInLakeland
ID: 24799886
Understanding why you wish to do such a thing may help in getting you the answers you need.
0
 
LVL 1

Expert Comment

by:nithinmohantk
ID: 24799898

Courtesy goes to Damage :: http://www.dreamincode.net/code/snippet2568.htm
Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
 
 
Public Class form1
 
    Public Structure SYSTEMTIME
        Public wYear As UInt16
        Public wMonth As UInt16
        Public wDayOfWeek As UInt16
        Public wDay As UInt16
        Public wHour As UInt16
        Public wMinute As UInt16
        Public wSecond As UInt16
        Public wMilliseconds As UInt16
    End Structure
 
    Declare Function GetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32
 
    Declare Function SetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32
 
    Public Sub GetTime()
        ' Call the native GetSystemTime method
        ' with the defined structure.
        Dim st As New SYSTEMTIME
        GetSystemTime(st)
 
        ' Show the current time.
        MessageBox.Show("Current Time: " & st.wHour.ToString() & ":" & st.wMinute.ToString())
    End Sub
 
    Public Sub SetTime()
        ' Call the native GetSystemTime method
        ' with the defined structure.
        Dim st As New SYSTEMTIME
        GetSystemTime(st)
 
        ' Set the system clock ahead one hour.
        st.wDay = Convert.ToUInt16(((CInt(st.wDay) + 1)))
        SetSystemTime(st)
 
    End Sub
 
 
 
 
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SetTime()
    End SubA
End Class

Open in new window

0
 
LVL 1

Author Comment

by:bkourouma
ID: 24801203
Hi thanks

The code below has a problem:

1 -
   ' Set the system clock ahead one hour.
        st.wDay = Convert.ToUInt16(((CInt(st.wDay) + 1)))
does not set the hour but rather the day one day ahead.

2 -
my dev computer is xp and  GetSystemTime(st) get me the correct date date but one hour back


3-
the   SetSystemTime(st) function does not affect my actuel system datetime.
Even calling GetSystemTime(st) after the SetSystemTime(st)  shows the unchanged datetime.


I am using asp.net not winform.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
nithinmohantk earned 500 total points
ID: 24801488
Whether windows forms or web from the

Declare Function GetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32
 
    Declare Function SetSystemTime Lib "Kernel32.dll" (ByRef lpSystemTime As SYSTEMTIME) As UInt32
 
will be same only. coz we are utilize windows Kernel32.dll COM api

more overloads can be found here

http://msdn.microsoft.com/en-us/library/ms172517.aspx 

0
 
LVL 1

Expert Comment

by:nithinmohantk
ID: 24801509
just a continuation...

As far as i know ASP.NET WebForms also can access Windows COM API's the same way we use for windows forms, by setting proper permissions.

Except certain api calls specific to Windows UI Api
0
 
LVL 1

Expert Comment

by:nithinmohantk
ID: 24801520
sorry to bump again,

the above posted link was for Windows CE

already some topic is there in Expert Exchange, so browse through here.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21405341.html 

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question