3 Replies - 28771 Views - Last Post: 20 September 2011 - 06:34 PM Rate Topic: -----

#1 lavender07   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-September 11

how to update system time using vb.net code

Posted 19 September 2011 - 06:22 PM

hi all... i have been looking for a code to change date time in kernel32,
which is I will get a date time from server and update current PC date and time based on server date and time.

I got this code from internet...

 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 Auto Function GetSystemTime Lib "Kernel32.dll" _
        (ByRef lpSystemTime As SYSTEMTIME) As UInt32

    Declare Auto 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.
        MsgBox("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.wHour = Convert.ToUInt16((CInt(st.wDay) + 1))
        SetSystemTime(st)

        MsgBox("Current dat3e: " & st.wHour.ToString()) '_
        ' & ":" & st.wMinute.ToString())


    End Sub



there is no error with this code... but nothing happens when i'm changing the date...
i'm using visual studio 2010.. can anyone show me how to update current PC system date and time??

Thank so much...

This post has been edited by macosxnerd101: 19 September 2011 - 06:36 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to update system time using vb.net code

#2 raziel_   User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,281
  • Joined: 25-March 09

Re: how to update system time using vb.net code

Posted 20 September 2011 - 04:31 AM

uhm can it be because you get the current system time and then set it to the same system i mean your GetTime() method get the PC time not the server time
Was This Post Helpful? 0
  • +
  • -

#3 iamnotgeek   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 27
  • Joined: 17-July 11

Re: how to update system time using vb.net code

Posted 20 September 2011 - 10:02 AM

dunno much abt vb.net but u can do it in batch programming in a single step
pass this argument(modify system time) to cmd : Time <the time>
format of time is : hh:mm:ss.ms (ms is millisecond)(hrs as per 24-hr clock)
this will allow u to directly change time.
in the same way for date its :Date <the date>
format of date is :mm-dd-yy

so u cud create following batch file using vb.net
@echo off
Time a 
Date b


a is the user defined time as per above mentioned format
b is the user defined date as above mentioned format
[note: save the file with .bat as extension]

u may create and call this batch file or directly pass those arguments i mentioned

hope it helps :)

This post has been edited by iamnotgeek: 20 September 2011 - 10:13 AM

Was This Post Helpful? 1
  • +
  • -

#4 lavender07   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-September 11

Re: how to update system time using vb.net code

Posted 20 September 2011 - 06:34 PM

View PostNoBrain, on 20 September 2011 - 04:31 AM, said:

uhm can it be because you get the current system time and then set it to the same system i mean your GetTime() method get the PC time not the server time



hi..thx...
yesterday i found out that my pc is running on window 7...
so there are no privillage to simply change the system date n time...
maybe that the problem.. but i'm afraid to change the privillage due to the pc will running silly after that...

huhuhu...

View Postiamnotgeek, on 20 September 2011 - 10:02 AM, said:

dunno much abt vb.net but u can do it in batch programming in a single step
pass this argument(modify system time) to cmd : Time <the time>
format of time is : hh:mm:ss.ms (ms is millisecond)(hrs as per 24-hr clock)
this will allow u to directly change time.
in the same way for date its :Date <the date>
format of date is :mm-dd-yy

so u cud create following batch file using vb.net
@echo off
Time a 
Date b


a is the user defined time as per above mentioned format
b is the user defined date as above mentioned format
[note: save the file with .bat as extension]

u may create and call this batch file or directly pass those arguments i mentioned

hope it helps :)


hi... that's rite...
i am now searching how to
1)get server date n time
2)put it in a notepad
3)run .bat file that can read from (2) notepad
4)update system time

can u teach me how to do it for no(3)?
thanx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1