Jump to content

Atomic Clock/NTP


Guest Hermies
 Share

Recommended Posts

Guest Hermies

I am trying to write a program that will only work on certain days of the week at certain times. The problem is that it is easy for a user to change the date/time on there machine . Since the program already requires an Internet connection I was wondering if it is possible to use the internet to get the current time. I know many web pages have the NPT info on them and I could grab that, but I dont know how to grab info without opening any visible programs.

Thanks in advance

Link to comment
Share on other sites

Open the page in a hidden window (SW_HIDE) and have it grab the text and use that. You could get a simple geocities site or any free host at that and put a clock of your own on it, in html, so that is the only text there. "ControlGetText" would then be used to get the information and use it.

Hope that helped!

-Para

Link to comment
Share on other sites

I am trying to write a program that will only work on certain days of the week at certain times. The problem is that it is easy for a user to change the date/time on there machine . Since the program already requires an Internet connection I was wondering if it is possible to use the internet to get the current time.  I know many web pages have the NPT info on them and I could grab that, but I dont know how to grab info without opening any visible programs.

Thanks in advance

<{POST_SNAPBACK}>

If you have a windows system locally... or someother that can respond to Windows "net" command:

C:\Documents and Settings\Administrator>net time \\sodium
Current time at \\sodium is 1/11/2005 5:19 PM

The command completed successfully.
Link to comment
Share on other sites

I am trying to write a program that will only work on certain days of the week at certain times. The problem is that it is easy for a user to change the date/time on there machine . Since the program already requires an Internet connection I was wondering if it is possible to use the internet to get the current time.  I know many web pages have the NPT info on them and I could grab that, but I dont know how to grab info without opening any visible programs.

Thanks in advance

<{POST_SNAPBACK}>

Hello Hermies i use this Mody script ,i found this exampel on the Autoit3 forums) :D

Test it out :idiot:

I love it^^ you must make a ini file for it! :lol:

If WinExists("%_StartClock_%") Then;Checks to see if StartClock is already running
   Exit
EndIf

#include <GUIConstants.au3>

Opt("GuiOnEventMode", 1)
Opt("GUICoordMode", 1)
Opt ("WinTitleMatchMode", 4)
Opt ("WinTextMatchMode", 2)
Opt ("WinWaitDelay", 10)

AutoItWinSetTitle("%_StartClock_%")
ProcessSetPriority("StartClock.exe", 0)

;PREDEFINED VARIABLES
$Button1POS = ControlGetPos( "classname=Shell_TrayWnd", "", "Button1");Start button NEW replace $Button1POS eventually
$ReBarPOS = ControlGetPos("classname=Shell_TrayWnd", "", "ReBarWindow321");entire runningApp and quicklaunch area
$GetTime = FileGetTime(@ScriptDir & "\THC 1.1 Beta.ini", 0, 1);checks to see when INI was last changed
$Btn_Sized = ""
$Btn_Date = ""
$Btn_Time = ""
$Btn_Sec = ""
$Time = ""
$DDate = ""
$Date = ""
$HHour = @HOUR
$MMin = @MIN
$SSec = @SEC

If FileExists(@ScriptDir & "\THC 1.1 Beta.ini") Then
   ReadINI()
Else
   MakeINI()
EndIf

Opt ("TrayIconHide", $HideTrayIcon)

If $BeginAtStartup = 1 Then
   RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "StartClock", "REG_SZ", @ScriptFullPath)
Else
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "StartClock")
EndIf

If $DisableHotkeys = 4 Then
   HotKeySet( "F5", "ExitScript"); 
   HotKeySet( "F6", "Config");
EndIf

ResizBtn()
AdlibEnable( "Watch", 250)

Do
  ;DYNAMIC OPTIONS
   If FileGetTime(@ScriptDir & "\THC 1.1 Beta.ini", 0, 1) <> $GetTime Then
      ReadINI()
      If $HideTrayIcon = 4 Then;HideTrayIcon
         $HideTrayIcon = 1
      Else
         $HideTrayIcon = 0
      EndIf
      Opt ("TrayIconHide", $HideTrayIcon)
      If $BeginAtStartup = 1 Then
         RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "StartClock", "REG_SZ", @ScriptFullPath)
      Else
         RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "StartClock")
      EndIf
      If $DisableHotkeys = 4 Then
         HotKeySet( "F5", "ExitScript"); 
         HotKeySet( "F6", "Config"); 
      Else
         HotKeySet( "F5")
         HotKeySet( "F6")
      EndIf
      $Btn_Sized = StringLen(String($Time)) * 6 + $Btn_Date - $Btn_Time + $Btn_Sec
   EndIf
   
  ;SET SECONDS PROPERTIES
   If $ShowSeconds = 1 Then
      $SSec = @SEC
      If $SSec = 00 Then $MMin = @MIN
      $Sec = ":" & $SSec
      $Btn_Sec = 12
   Else
      $Sec = ""
      $Btn_Sec = ""
   EndIf
  ;SET DATE PROPERTIES
   If $ShowDate = 1 Then
      CallDate()
   Else
      $Date = ""
      $Btn_Date = ""
   EndIf
   
  ;SET TIME PROPERTIES
   If $MMin = 00 Then $HHour = @HOUR
   If $ClockType = 1 Then
      If $HHour <= 11 And Not $HHour = 00 Then
         $Hour = 24 + $HHour - 24
         $AMPM = " AM"
      ElseIf $HHour > 12 Then
         $Hour = $HHour - 12
         $AMPM = " PM"
      ElseIf $HHour = 12 Then
         $Hour = $HHour
         $AMPM = " PM"
      ElseIf $HHour = 00 Then
         $Hour = "12"
         $AMPM = " AM"
      EndIf
      $Time = $Hour & ":" & $MMin & $Sec & $AMPM & $Date
      $Btn_Time = ""
   Else
      $Time = $HHour & ":" & $MMin & $Sec & $Date
      $Btn_Time = "";12
   EndIf
   $Btn_Sized = StringLen(String($Time)) * 6 + $Btn_Date - $Btn_Time + $Btn_Sec
   Sleep(1000)
Until 1 <> 1

;FUNCTIONS
Func Watch()
  If ControlGetPos( "classname=Shell_TrayWnd", "", "Button1") <> $Pre_Watch Then
     ResizBtn()
  EndIf
EndFunc

Func ResizBtn()
   $TrayNEW = ControlGetPos("classname=Shell_TrayWnd", "", "ReBarWindow321")
   If $ReBarPOS[3] <> $TrayNEW[3] Then RefreshTray();drastic theme changes
   If $ReBarPOS[2] > $ReBarPOS[3] Then;entire tray width greater than height
      ControlMove("classname=Shell_TrayWnd", "", "ReBarWindow321", $ReBarPOS[0] + $Btn_Sized, $ReBarPOS[1], $ReBarPOS[2] - $Btn_Sized, $ReBarPOS[3])
   EndIf
   ControlMove("classname=Shell_TrayWnd", "", "Button1", $Button1POS[0], $Button1POS[1], $Button1POS[2] + $Btn_Sized, $Button1POS[3]);x, y, width, height
   ControlSetText("classname=Shell_TrayWnd", "", "Button1", $Time)
   GLOBAL $Pre_Watch = ControlGetPos( "classname=Shell_TrayWnd", "", "Button1")
EndFunc  ;==>ResizBtn

Func CallDate()
   If @MON = 1 Then
      $mon = "DirtyBanditos 2004-2005 Jan"
   ElseIf @MON = 2 Then
      $mon = "DirtyBanditos 2004-2005 Feb"
   ElseIf @MON = 3 Then
      $mon = "DirtyBanditos 2004-2005 Mar"
   ElseIf @MON = 4 Then
      $mon = "DirtyBanditos 2004-2005 Apr"
   ElseIf @MON = 5 Then
      $mon = "DirtyBanditos 2004-2005 May"
   ElseIf @MON = 6 Then
      $mon = "DirtyBanditos 2004-2005 June"
   ElseIf @MON = 7 Then
      $mon = "DirtyBanditos 2004-2005 July"
   ElseIf @MON = 8 Then
      $mon = "DirtyBanditos 2004-2005 Aug"
   ElseIf @MON = 9 Then
      $mon = "DirtyBanditos 2004-2005 Sept"
   ElseIf @MON = 10 Then
      $mon = "DirtyBanditos 2004-2005 Oct"
   ElseIf @MON = 11 Then
      $mon = "DirtyBanditos 2004-2005 Nov"
   ElseIf @MON = 12 Then
      $mon = "DirtyBanditos 2004-2005 Dec"
   EndIf
   $Date = " - " & $mon & " " & @MDAY
   $Btn_Date = (StringLen(String($Date)) * 2) - 6
EndFunc  ;==>CallDate

Func RefreshTray()
   ProcessWaitClose( "net.exe" )
   Opt ("TrayIconHide", 0)
   Opt ("TrayIconHide", 1)
   Opt ("TrayIconHide", $HideTrayIcon)
   $Button1TXT = ControlGetText("classname=Shell_TrayWnd", "", "Button1");Start Button
   $Button1POS = ControlGetPos( "classname=Shell_TrayWnd", "", "Button1");Start Button NEW replace $Button1POS eventually
   $ReBarPOS = ControlGetPos("classname=Shell_TrayWnd", "", "ReBarWindow321");entire runningApp and quicklaunch area
EndFunc  ;==>RefreshTray

Func ReadINI()
   GLOBAL $ShowSeconds = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "ShowSeconds", "4")
   GLOBAL $ClockType = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "ClockType", "1")
   GLOBAL $ShowDate = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "ShowDate", "4")
   GLOBAL $HideTrayIcon = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "HideTrayIcon", "4")
   GLOBAL $BeginAtStartup = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "BeginAtStartup", "4")
   GLOBAL $DisableHotkeys = IniRead(@ScriptDir & "\THC 1.1 Beta.ini", "Settings", "DisableHotkeys", "4")
EndFunc

Func MakeINI()
   GuiCreate("StartClock Configuration", 248, 148,(@DesktopWidth-224)/2, (@DesktopHeight-178)/2 , 0x12CA0000)
   GUISetState (@SW_SHOW)
   $Label_Options = GuiCtrlCreateLabel("Options:", 15, 10, 60, 20)
   GLOBAL $Radio_12Hour = GuiCtrlCreateRadio("12 Hour Clock", 15, 30, 100, 20)
   GLOBAL $Radio_24Hour = GuiCtrlCreateRadio("24 Hour Clock", 15, 50, 90, 20)
   GLOBAL $Checkbox_ShowSeconds = GuiCtrlCreateCheckbox("Show Seconds", 15, 70, 90, 20)
   GLOBAL $Checkbox_ShowDate = GuiCtrlCreateCheckbox("Show Date", 15, 90, 70, 20)
   GLOBAL $Checkbox_Tray = GuiCtrlCreateCheckbox("Show Tray Icon", 140, 30, 100, 20)
   GLOBAL $Checkbox_Startup = GuiCtrlCreateCheckbox("Begin at Startup", 140, 50, 100, 20)
   GLOBAL $Checkbox_Hotkeys = GuiCtrlCreateCheckbox("Disable Hotkeys", 140, 70, 100, 20)
   GLOBAL $Exit1 = GuiCtrlCreateButton("Exit", 78, 120, 90, 20)
   
   If FileExists (@ScriptDir & "\THC 1.1 Beta.ini") Then
      ReadINI()
      If $ClockType = 4 Then
         GUICtrlSetState($Radio_24Hour, 1)
      Else
         GUICtrlSetState($Radio_12Hour, 1)
      EndIf
      GUICtrlSetState ( $Checkbox_ShowSeconds, $ShowSeconds )
      GUICtrlSetState ( $Radio_12Hour, $ClockType )
      GUICtrlSetState ( $Checkbox_ShowDate, $ShowDate )
      GUICtrlSetState ( $Checkbox_Tray, $HideTrayIcon )
      GUICtrlSetState ( $Checkbox_Startup, $BeginAtStartup )
      GUICtrlSetState ( $Checkbox_Hotkeys, $DisableHotkeys )
   Else
      GUICtrlSetState ( $Checkbox_ShowSeconds, 4)
      GUICtrlSetState ( $Radio_12Hour, 1 )
      GUICtrlSetState ( $Checkbox_ShowDate, 4)
      GUICtrlSetState ( $Checkbox_Tray, 4)
      GUICtrlSetState ( $Checkbox_Startup, 4)
      GUICtrlSetState ( $Checkbox_Hotkeys, 4)
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "ShowSeconds", 4 )
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "ClockType", 1 )
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "ShowDate", 4 )
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "HideTrayIcon", 4 )
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "BeginAtStartup", 4 )
      IniWrite ( "THC 1.1 Beta.ini", "Settings", "DisableHotkeys", 4 )
      ReadINI()
   EndIf
   
   GUICtrlSetOnEvent($Radio_12Hour, "ButtonPressed")
   GUICtrlSetOnEvent($Radio_24Hour, "ButtonPressed")
   GUICtrlSetOnEvent($Checkbox_ShowSeconds, "ButtonPressed")
   GUICtrlSetOnEvent($Checkbox_ShowDate, "ButtonPressed")
   GUICtrlSetOnEvent($Checkbox_Tray, "ButtonPressed")
   GUICtrlSetOnEvent($Checkbox_Startup, "ButtonPressed")
   GUICtrlSetOnEvent($Checkbox_Hotkeys, "ButtonPressed")
   GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "ExitPressed")
   GuiSetOnEvent($GUI_EVENT_CLOSE, "ExitPressed")
EndFunc

Func ButtonPressed()
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "ShowSeconds", GUICtrlRead( $Checkbox_ShowSeconds ) )
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "ClockType", GUICtrlRead( $Radio_12Hour ) )
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "ShowDate", GUICtrlRead( $Checkbox_ShowDate ) )
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "HideTrayIcon", GUICtrlRead( $Checkbox_Tray ) )
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "BeginAtStartup", GUICtrlRead( $Checkbox_Startup ) )
   IniWrite ( "THC 1.1 Beta.ini", "Settings", "DisableHotkeys", GUICtrlRead( $Checkbox_Hotkeys ) )
EndFunc

Func ExitPressed()
   GUIDelete()
EndFunc

Func Config()
   GUIDelete()
   MakeINI()
EndFunc  ;==>Config

Func ExitScript()
   AdlibDisable()
   Opt ( "TrayIconHide", 0)
   Opt ("TrayIconHide", 1)
   Opt ("TrayIconHide", $HideTrayIcon)
   EndFunc

The Ini wat you ned for this!

[Settings]
ShowSeconds=1
ClockType=4
ShowDate=1
HideTrayIcon=4
BeginAtStartup=1
DisableHotkeys=4
Edited by DirtyBanditos
Link to comment
Share on other sites

considering you can put the entire CMD window into the clipboard? I don't think that it can be read at all. [/sarcasm].

A standard select all, control insert command would do it....

WinActivate($cmd)
MouseClick($secondary,5,150,1,0); context menu in titlebar.
Send("ES{enter}"); selects all text in the buffer and stuffs it in the clipboard.

then use clipget() to read it into your program. I do it all the time with AS400 emulators. The DOS box is no different, just a little more cranky.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Guest Hermies

I thought about the Webpage, and there is a Government issued one that just displays time/date, but that still requires a web browser to be opened and read it. I would perfer a way for the script to get it if possible. The Script included seems to be relying only on local time. I am going to go through it again, but the clock seems to be based on system time not a time server that the user has no control over.

SMB is not an option because I have no way of knowing if there is a SMB server in the area, and since this is going to be used on laptops there may or may not be one on the given network even if there is one at home.

Thanks

Please keep ideas comeing.

Link to comment
Share on other sites

considering you can put the entire CMD window into the clipboard?  I don't think that it can be read at all. [/sarcasm].

You can pipe it out from cmd, to a text file. Then read it. With example: " > temp.txt" at the end of the command.
Link to comment
Share on other sites

You can just use InetGet to download the output of a php-script which outputs current date.

[quote name='d2hacker88' date='Jan 6 2005, 05:10 PM']Can someone please help me out with autoit like gimme a link on how to use it cause i have no experience with computer languages and i'd like to make a program with autoit in order to empress my computer teacher.[right][snapback]52215[/snapback][/right][/quote]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...