Solved

change system clock through asp.net

Posted on 2009-07-07
7
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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