Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change system clock through asp.net

Posted on 2009-07-07
7
Medium Priority
?
325 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

604 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