1

I asked how to check modify timestamps with BAT files and launch a command based on an if statement and Wimmel asked if I could use VBScript instead of Batch Files. I think this is a grand idea. This leads to another question

Can I access the VBScript functionality with JavaScript, while still being compatible Windows XP to Current? (specifically checking file modify timestamp and running a command depending on how recently modified)

Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341
  • have a look at [HTA](http://msdn.microsoft.com/en-us/library/ms536496%28v=vs.85%29.aspx) can be written in vb or javascript. Not sure what you mean by accessing vbscript from javascript – mplungjan Jun 14 '11 at 19:35

2 Answers2

1

Not sure that it is a good idea, but yes, you can use JavaScript (actually, JScript) instead of VBScript. Just use ActiveXObject class instead of CreateObject function that is used in VBScript to create objects.

Here is a code that reads the file modify timestamp using Windows Scripting and JScript:

var o = new ActiveXObject("Scripting.FileSystemObject");
var file = o.GetFile("c:\\temp\\test.js");
WScript.Echo(file.DateLastModified);

For more information, see JScript documentation and Windows Script Host documentation

  • I probably shouldn't have posted this remark... I don't really have any serious reason not to use JScript with Windows Scripting. ActiveX objects are more "native" for VBScript, so I would choose VB for the tasks like this one, but it's very subjective. – Sergey Misura Jun 14 '11 at 20:19
1

Even though there are probably easier ways to achieve what you want to do, I had a go at trying the more theoretical part of your question, and apparently all the things we need are there.

Here is what I tried:

test.js:

WshShell = WScript.CreateObject("WScript.Shell");
var result = WshShell.Run("test.vbs", 0, true);
WSH.Echo(result);

test.vbs:

WSH.Echo "test.vbs"
WSH.Quit 5
Xyz
  • 5,955
  • 5
  • 40
  • 58
Jan-Peter Vos
  • 3,157
  • 1
  • 18
  • 21
  • That is not what I meant. I did not mean, execute a VBScript with a JScript. I meant access equivalent functionality using JScript. – 700 Software Jun 14 '11 at 19:54
  • ah ok, not sure what you are looking for then. I guess all languages have the power to solve all logical problems, so what can be solved in VBScript van also be solved in JScript. Just in a slightly different way. The real difference can be in the API. but JScript and VBScript mostly use ActiveX components for these using `WScript.CreateObject` and the resulting objects are not tied to the language. – Jan-Peter Vos Jun 14 '11 at 20:16