1

I want to see if a lock file modify date is more than a 5 seconds ago or it in the future (indicating the PC clock was changed back).

How can I say

  • if file.modifydate < now - 5 seconds or modifydate > now
    • run command a (command a will launch my Java app)
  • else
    • run command b (command b will send a UDP packet to a localhost port)
700 Software
  • 85,281
  • 83
  • 234
  • 341
  • does it need to be a batch file, or is vbscript acceptable too? – wimh Jun 14 '11 at 19:07
  • That is an interesting idea. I think vbscript will work fine. Can we launch vbscript without showing any terminal windows? – 700 Software Jun 14 '11 at 19:11
  • when you use wscript.exe to start the script, you don't see anything unless you output anything in the script. – wimh Jun 14 '11 at 19:52
  • It's hard to get the seconds part of a file with pure batch, you normaly get only something like `16.06.2011 07:44` with `dir` or `FOR %a in (myfile) do echo %~ta` – jeb Jun 16 '11 at 05:44
  • I will be using either VBScript or JavaScript. @Wimmel, please make an answer so I can accept. – 700 Software Jun 16 '11 at 13:27
  • @George, I think it is better if you describe in an answer how you have solved your problem, and accept that as answer. – wimh Jun 17 '11 at 06:36

1 Answers1

2

As Wimmel suggested, I will be using VBScript - well actually I will be using JScript in the same way VBScript would normally be used... because I am already familiar with JavaScript.

I posted this question: Windows XP and Up: JavaScript instead of VBScript?

Which has the code I will be using

for checking modify date/time

var o = new ActiveXObject("Scripting.FileSystemObject");
var file = o.GetFile("c:\\temp\\test.js");
// WScript.Echo(file.DateLastModified); // This is the modify date/time with seconds

and code to exec my Java process

WshShell = WScript.CreateObject("WScript.Shell");
var result = WshShell.Run("command-goes-here", 0, true);
// WSH.Echo(result); // this is the exit code

command b will be to send the UDP packet using one of the suggestions from Windows BAT or CMD: send some data to a localhost udp port.

The commands would probably be the same if I used VBScript/JScript so they should work fine.

The only thing missing is: VBScript/JScript Networking: Connect either UDP or TCP

If I could use a native function, it would definitely be better than an exec of command b.

Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341