Solved

change system clock through asp.net

Posted on 2009-07-07
7
319 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now