?
Solved

change system clock through asp.net

Posted on 2009-07-07
7
Medium Priority
?
324 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Accepted Solution

by:
nithinmohantk earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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