Windows XP 及更高版本:JavaScript 而不是 VBScript? [英] Windows XP and Up: JavaScript instead of VBScript?

查看:33
本文介绍了Windows XP 及更高版本:JavaScript 而不是 VBScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我询问了 如何使用 BAT 文件检查修改时间戳以及启动基于 if 语句的命令,Wimmel 询问我是否可以使用 VBScript 而不是批处理文件.我认为这是一个伟大的想法.这就引出了另一个问题

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

我能否使用 JavaScript 访问 VBScript 功能,同时仍然兼容 Windows XP 到 Current?(专门检查文件修改时间戳并根据最近修改的方式运行命令)

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)

推荐答案

不确定这是个好主意,但是是的,您可以使用 JavaScript(实际上是 JScript)而不是 VBScript.只需使用 ActiveXObject 类而不是 VBScript 中使用的 CreateObject 函数来创建对象.

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.

这是使用 Windows 脚本和 JScript 读取文件修改时间戳的代码:

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);

有关详细信息,请参阅 JScript 文档Windows 脚本宿主文档

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

这篇关于Windows XP 及更高版本:JavaScript 而不是 VBScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆