Results 1 to 12 of 12

Thread: [Resolved] time update on windows ce device not works

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    [Resolved] time update on windows ce device not works

    i,m not sure if i,am in the right group... but my problem is i made a smartdevice application ( windows ce device, scanner ) the program should update
    time ( using a nisttime server ) the program works on my windows laptop , it shows the time and updates it ( run as administrator )

    on my windows ce device the program is running and shows the time, but it,s not update it !!! ( no possibility also to runs as admin, not sure if this is the problem, as i also can not change the uAC settings in visual studio 2008 on a smartdevice application ) below the code ;

    ================== code =====================================

    Code:
    Imports System.IO
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Runtime.InteropServices
    
    
    Public Class Form1
    
        Public Shared LastSysTime As DateTime
        Public Shared maand As String
        Public Shared dag As String
        Public Shared uur As String
        Public Shared jaar As String
        Public minuut As String
    
        Public Function GetNISTTime(ByVal host As String) As DateTime
    
            Dim timeStr As String
    
            Try
                Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
                LastSysTime = DateTime.UtcNow()
                timeStr = reader.ReadToEnd()
                reader.Close()
            Catch ex As SocketException
                Label1.Text = ex.Message
            Catch ex As Exception
                Label1.Text = ex.Message
            End Try
    
            Dim jd As Integer = Integer.Parse(timeStr.Substring(1, 5))
            Dim yr As Integer = Integer.Parse(timeStr.Substring(7, 2))
            Dim mo As Integer = Integer.Parse(timeStr.Substring(10, 2))
            Dim dy As Integer = Integer.Parse(timeStr.Substring(13, 2))
            Dim hr As Integer = Integer.Parse(timeStr.Substring(16, 2))
            Dim mm As Integer = Integer.Parse(timeStr.Substring(19, 2))
            Dim sc As Integer = Integer.Parse(timeStr.Substring(22, 2))
            Dim Temp As Integer = CInt(AscW(timeStr(7)))
    
            maand = mo
            dag = dy
            uur = hr
            jaar = yr
            minuut = mm
    
            Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
    
        End Function
    
        Private Structure SYSTEMTIME
            Dim wYear As Short
            Dim wMonth As Short
            Dim wDayOfWeek As Short
            Dim wDay As Short
            Dim wHour As Short
            Dim wMinute As Short
            Dim wSecond As Short
            Dim wMilliseconds As Short
        End Structure
    
        Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME) As Long
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Label1.Text = GetNISTTime("utcnist.colorado.edu").ToString
    
                Dim timeStru As SYSTEMTIME
    
                timeStru.wDay = dag
                timeStru.wHour = uur
                timeStru.wMinute = minuut
                timeStru.wMonth = maand
    
                timeStru.wYear = 2021  'set the new time
    
                SetSystemTime(timeStru)
    
            Catch ex As Exception
    
            End Try
    
        End Sub
    End Class
    Last edited by kriszty99; Sep 28th, 2021 at 06:49 AM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    Hi,

    Thanks for the reply, even if i do not use the varaibles, it only shows the time, but not updating it on the device ... problem is that the devices is not holding time after a reboot so therefore i wrote this vb app
    it does work on windows but not excatly on the CE device

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,284

    Re: time update on windows ce device not works

    Try this...

    Code:
    Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME) As Integer
    Code:
    Dim timeStru As New SYSTEMTIME
    
    timeStru.wDay = CShort(dag)
    timeStru.wHour = CShort(uur)
    timeStru.wMinute = CShort(minuut)
    timeStru.wMonth = CShort(maand)
    
    timeStru.wYear = CShort(2021) 'set the new time
    
    MsgBox(SetSystemTime(timeStru))

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    Hi Paul,

    Nope, same result, i got the right time in the app ( and message ) but it,s not updating it on my CE device ( under w1o as admin it does update )

    kriszty, ...

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    is this problem related because i can not run the app as administrator ( not sure how to do this on a windows CE scanner device )

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,284

    Re: time update on windows ce device not works

    Project-->Properties-->Application-->View UAC Settings-->requestedExecutionLevel

    follow the instructions in your app.manifest

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    UAC settings are grayed out with a mobile application , with a normal windows application i can choose, but not with a mobile app ) should be a other way to solve this...

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,284

    Re: time update on windows ce device not works

    I don't have experience with CE. I'm just giving you general advice. You'll have to wait for someone with experience in CE...

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    yes i think so.
    anyway thanks for trying to help

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    just rewrote it, i know it,s not perfect but it,s working now
    Code:
    ;=================  code =======================
    
    Imports System.IO
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        Inherits System.Windows.Forms.Form
    
        Public Shared LastSysTime As DateTime
        Public Shared maand As String
        Public Shared dag As String
        Public Shared uur As Short
        Public Shared jaar As String
        Public minuut As String
    
    
    
    #Region " Windows Form Designer generated code "
    
        Public Sub New()
            MyBase.New()
    
            'This call is required by the Windows Form Designer.
            InitializeComponent()
    
            'Add any initialization after the InitializeComponent() call
    
        End Sub
    
        'Form overrides dispose to clean up the component list.
    
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
    
    
    #End Region
    
        Private Structure SYSTEMTIME
            Public Year As Short
            Public Month As Short
            Public DayOfWeek As Short
            Public Day As Short
            Public Hour As Short
            Public Minute As Short
            Public Second As Short
            Public Milliseconds As Short
        End Structure
    
        <DllImport("coredll.dll")> _
        Private Shared Function SetSystemTime(ByRef time As SYSTEMTIME) As Boolean
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Try
             
                Label1.Text = GetNISTTime("utcnist.colorado.edu").ToString
    
    
                Dim idag As DateTime = Now().AddHours(0).AddMinutes(0).ToUniversalTime
                Dim s As New SYSTEMTIME
    
    
    
                s.Year = 2021
                s.Month = TextBox1.Text
    
                s.Day = TextBox2.Text
                s.Hour = TextBox3.Text + 6
                s.Minute = TextBox4.Text
                ' s.Second = idag.Second
                ' s.Milliseconds = idag.Millisecond
    
                SetSystemTime(s)
            Catch ex As SocketException
                Label1.Text = ex.Message
            Catch ex As Exception
                Label1.Text = ex.Message
            End Try
    
            Close()
    
    
        End Sub
    
        Public Function GetNISTTime(ByVal host As String) As DateTime
    
            Dim timeStr As String
    
            Try
                Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
                LastSysTime = DateTime.UtcNow()
                timeStr = reader.ReadToEnd()
                reader.Close()
            Catch ex As SocketException
                Label1.Text = ex.Message
            Catch ex As Exception
                Label1.Text = ex.Message
            End Try
    
            Dim jd As Integer = Integer.Parse(timeStr.Substring(1, 5))
            Dim yr As Integer = Integer.Parse(timeStr.Substring(7, 2))
            Dim mo As Integer = Integer.Parse(timeStr.Substring(10, 2))
            Dim dy As Integer = Integer.Parse(timeStr.Substring(13, 2))
            Dim hr As Integer = Integer.Parse(timeStr.Substring(16, 2))
            Dim mm As Integer = Integer.Parse(timeStr.Substring(19, 2))
            Dim sc As Integer = Integer.Parse(timeStr.Substring(22, 2))
            Dim Temp As Integer = CInt(AscW(timeStr(7)))
    
            maand = mo
            dag = dy
            uur = hr
            jaar = yr
            minuut = mm
    
            Return New DateTime(yr + 2000, mo, dy, hr, mm, sc)
    
        End Function
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                Label1.Text = GetNISTTime("utcnist.colorado.edu").ToString
                TextBox1.Text = maand
                TextBox2.Text = dag
                TextBox3.Text = uur
                TextBox4.Text = minuut
    
            Catch ex As SocketException
                Label1.Text = ex.Message
            Catch ex As Exception
                Label1.Text = ex.Message
            End Try
    
        End Sub
    End Class
    Last edited by si_the_geek; Sep 28th, 2021 at 05:55 AM. Reason: added Code tags

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,284

    Re: time update on windows ce device not works

    What happens if you run it when TextBox1.Text = “” ???
    Turn Option Strict on for all of your projects, and the compiler will insist you enter better code…

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    11

    Re: time update on windows ce device not works

    did not try it yet , i still have to streamline my code... but was happy it works now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width