Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch file to set a datestamp & run a html page a year later  (Read 3924 times)

0 Members and 1 Guest are viewing this topic.

c hay

    Topic Starter


    Starter

    Hello

    Im looking for help to create a batch file which runs at startup from task scheduler that can set a datestamp in the file when it first runs and then runs a html page but only after a year has passed. So i suppose that the file would need to compare the inital date every time it runs and do an IF command. Im am struggling to find the best way to begin with so any help would be greatly apprieciated, thanks in advance!   

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: batch file to set a datestamp & run a html page a year later
    « Reply #1 on: June 28, 2010, 04:13:45 PM »
    You should be able to use the task scheduler to schedule the job annually. On the schedule tab choose monthly, then click select months and unclick all the months except one. This will be the month the job runs. Use the schedule tasks monthly to choose the absolute day of the month or the relative day of the month (ex: second Tuesday of the month)

    Not sure what you mean about setting a timestamp in the file. To run a HTML page use iexplore and pass the http address as the first parameter.

    Good luck.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    c hay

      Topic Starter


      Starter

      Re: batch file to set a datestamp & run a html page a year later
      « Reply #2 on: June 28, 2010, 04:43:37 PM »
      many thanks for your reply,

      The HTML idea comes from the need to inform users that their laptops need returning for its  annual health check etc (as i work in a school with lots of laptops) and wanted to be able to put the batch file in the laptop image so that when the image/OS is first run on each individual laptop the file looks at the current date, adds 365 days ( & checks this date every time the laptop is started) finally after the year has passed the HTML will pop up with the message prompt.
      Hope this makes sense and thanks again :)
       

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: batch file to set a datestamp & run a html page a year later
      « Reply #3 on: June 28, 2010, 08:54:22 PM »
      If you can put a small VBS file in the startup folder then this will be a breeze. Once the computer's annual check is complete, place a file called "timestamp" in C:\annualcheckup\ on each computer. It doesn't have to contain anything, except maybe a message saying something along the lines of "DO NOT MODIFY", etc. Then, place the following code inside a .vbs file (name it anything you want) and place it in the users' startup folder.

      Set objFS = CreateObject("Scripting.FileSystemObject")
      strFolder = "C:\annualcheckup"
      Set objFolder = objFS.GetFolder(strFolder)
      Set strfile = objFolder.Files("timestamp")
      if datediff("d",strFile.DateLastModified,Now) >= 365 Then
         'notice on year
         msgbox "Your computer is due for its yearly check."
      If DateDiff("d",strFile.DateLastModified,Now) >= 355 Then
         '10-day notice before year
         msgbox "Please remember to return your computer for a yearly check soon."
      end if


      The code will check to see if the file is 365 days old, then tell them they're due for a checkup, and if it's later than 355, then tell them to remember that their yearly check is soon.
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: batch file to set a datestamp & run a html page a year later
      « Reply #4 on: June 29, 2010, 07:38:45 AM »
      Batch code is terrible at date math, so I took a different approach by using the creation date of the Windows directory as the base date (this can be changed). By using the creation month and day and appending the current year, it became easy to calculate the next date the reminder should display.

      Code: [Select]
      @echo off
      setlocal enabledelayedexpansion

      for /f %%v in ('dir /a:d /tc c:\ ^| find /i "windows"') do (
        set filler=%%v
        set baseMon=!filler:~0,2!
        set baseDay=!filler:~3,2!
        set currYear=%date:~10,4%


      set nextDate=%baseMon%/%baseday%/%currYear%
      set currDate=%date:~4,10%

      if %currDate% EQU %nextDate% (
        iexplore "pointer to HTML page goes here"


      The snippet uses a date format of dow mm/dd/yyyy. If your machines are different, the snippet will need to be tweaked.

      What happens if the next run date falls on a weekend?

      Change the line where IE is launched to point to the HTML page to display.

      Good luck.  8)

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      c hay

        Topic Starter


        Starter

        Re: batch file to set a datestamp & run a html page a year later
        « Reply #5 on: June 30, 2010, 12:54:28 PM »
        Thanks helpmeh your solution seems to work the best in this situation although i have integrated the HTML option into it as there are more options to make it look pretty! (logo's etc) just one thing that i need further help with. Is there a way to hide the .vbs & still make it run as ammending the file attribute to hidden stops the script from running at all.

        Here is the script i have so far  :)

        Set objFS = CreateObject("Scripting.FileSystemObject")
        strFolder = "C:\annualcheckup"
        Set objFolder = objFS.GetFolder(strFolder)
        Set strfile = objFolder.Files("timestamp.txt")
        if datediff("d",strFile.DateLastModified,Now) >= 365 Then
           'notice on year
         
        Dim IE
        Set IE = CreateObject("InternetExplorer.Application")

        With IE
                .left=200
                .top=200
                .height=400
                .width=800
                .menubar=0
                .toolbar=0
                .statusBar=0
                .navigate "About:Blank"
                .visible=1
        End With

        With IE.document
                .Open
                .WriteLn "<HTML><HEAD>"
                .WriteLn "<TITLE>CNS</TITLE></HEAD>"
                .WriteLn "<BODY>"
                .WriteLn "Message Please return your laptop etc etc"
                .WriteLn "</BODY>"
                .WriteLn "</HTML>"
                .Close
        End With

        Set IE = Nothing
        WScript.Quit(0)
        end if

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: batch file to set a datestamp & run a html page a year later
        « Reply #6 on: June 30, 2010, 05:33:22 PM »
        Is it in the startup folder? I'm not sure why making the file hidden is preventing it from running.

        Maybe you should put it in the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
        registry key.
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        c hay

          Topic Starter


          Starter

          Re: batch file to set a datestamp & run a html page a year later
          « Reply #7 on: July 02, 2010, 12:15:33 PM »
          It was in the startup folder & would not run with a hidden file attribute - however i did as you suggested & it worked a treat! thanks - I am however still looking for a way to now change the file creation date (automatically) for the timestamp file when windows is first run, as the windows system date is generated from the bios date after the image is pulled down from the image server. This would mean that no alteration of the timestamp.txt would be needed as it would always be the date that windows was first run - which would be perfect ;)