//这是一段在网上找到的系统时间自动更新JS脚本,任意Web服务器都可以用来协对时间而且也不用vb来改时间,保存为*.js点击运行即可
//get HTTP Date: response from server, return approximate dateVal object
function getServerDate(serverHttpAddress, httpProxyAddress)
{
var xmlHttp = new ActiveXObject("msxml2.xmlhttp");
if(httpProxyAddress)
{
setProxy(2,proxyHttpAddress.replace("http://",""));
}
xmlHttp.open("GET", serverHttpAddress, 0);
ts=(new Date()).getTime();
WScript.Echo("Start time: " + ts);
xmlHttp.send();
tr=new Date();
WScript.Echo("End time: " + tr.getTime());
WScript.Echo("Server Time: " + Date.parse( xmlHttp.getResponseHeader('Date')));
//Thu, 1 Jan 09:47:01 GMT
tr.setTime(Date.parse( xmlHttp.getResponseHeader('Date')) + ((new Date()).getTime() - ts)/2);
//1230805540107
WScript.Echo("debug time: " + tr)
return tr;
//}
//catch(e)
//{
// return 0
//}
}
//set system time to dateString
///technet/scriptcenter/topics/networking/08_atnc_advanced.mspx
///technet/scriptcenter/guide/sas_wmi_fvwp.mspx?mfr=true
//0327073509.519000+480
function setSystemDate(dateString)
{
WScript.Echo("End time: " + dateString);
var oSvc = GetObject("winmgmts:\\\\.\\root\\cimv2");
oSvc.Security_.Privileges.AddAsString("SeSystemTimePrivilege", 1);
var e = new Enumerator(oSvc.execQuery("select * from win32_OperatingSystem", "WQL", 32));
//for (;!e.atEnd();e.moveNext())e.item().SetDateTime(dateString);
}
//generating the right WMI DATETIME fields
with(getServerDate("/")) //和哪一个HTTP服务器进行同步
{
setSystemDate("" +
getUTCFullYear() +
(getUTCMonth()<9?"0"+(getUTCMonth()+1):(getUTCMonth()+1)) +
(getUTCDate()<9?"0"+getUTCDate():getUTCDate()) +
(getUTCHours()<9?"0"+getUTCHours():getUTCHours()) +
(getUTCMinutes()<9?"0"+getUTCMinutes():getUTCMinutes()) +
(getUTCSeconds()<9?"0"+getUTCSeconds():getUTCSeconds()) +
".******+***");
}