посоветовали продолжать здесь:
+ добавлен лог для ошибок
? как бы покрасивее дату/время получать ?
? как бы пинговать компы перед коннектом ?
[more=листинг]var fs, a, ForAppending;
ForAppending = 8;
fs = new ActiveXObject("Scripting.FileSystemObject");
a = fs.OpenTextFile(".\\evtcollect.log", ForAppending, true);
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var arrComputers = new Array("HOME","ADMIN1","JUSEPPE");
var strBackup = "c:\\"
for (i = 0; i < arrComputers.length; i++)
{
var objWMIService = GetObject("winmgmts:{(Backup,Security)}\\\\" + arrComputers[i] + "\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTEventlogFile", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
for (; !enumItems.atEnd(); enumItems.moveNext())
{
var objItem = enumItems.item();
var strBackupFile = strBackup + arrComputers[i] + "_" + TimeNow() + "_" + objItem.LogfileName + ".evt";
try { objItem.BackupEventLog(strBackupFile) }
catch(e) { a.WriteLine(TimeNowLog() + arrComputers[i] + ": " + objItem.LogfileName + " couldn't be saved"); }
try { objItem.ClearEventLog() }
catch(e) { a.WriteLine(TimeNowLog() + arrComputers[i] + ": " + objItem.LogfileName + " couldn't be cleared"); }
}
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.MoveFile("\\\\" + arrComputers[i] + "\\c$\\*.evt", "\\\\HOME\\eventlog\\");
}
a.Close();
function TimeNow()
{
d = new Date();
var strNow = "";
strNow += LeadingZero(d.getFullYear()) + "_";
strNow += LeadingZero((d.getMonth()) + 1) + "_";
strNow += LeadingZero(d.getDate()) + "_";
strNow += LeadingZero(d.getHours()) + "_";
strNow += LeadingZero(d.getMinutes()) + "_";
strNow += LeadingZero(d.getSeconds());
return(strNow);
}
function TimeNowLog()
{
d = new Date();
var strNow = "";
strNow += LeadingZero(d.getFullYear()) + "/";
strNow += LeadingZero((d.getMonth()) + 1) + "/";
strNow += LeadingZero(d.getDate()) + " ";
strNow += LeadingZero(d.getHours()) + ":";
strNow += LeadingZero(d.getMinutes()) + ":";
strNow += LeadingZero(d.getSeconds()) + " ";
return(strNow);
}
function LeadingZero(intNum)
{
if (10 > intNum)
{ intNum = "0" + intNum;}
return(intNum);
}[/more]
+ добавлен лог для ошибок
? как бы покрасивее дату/время получать ?
? как бы пинговать компы перед коннектом ?
[more=листинг]var fs, a, ForAppending;
ForAppending = 8;
fs = new ActiveXObject("Scripting.FileSystemObject");
a = fs.OpenTextFile(".\\evtcollect.log", ForAppending, true);
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var arrComputers = new Array("HOME","ADMIN1","JUSEPPE");
var strBackup = "c:\\"
for (i = 0; i < arrComputers.length; i++)
{
var objWMIService = GetObject("winmgmts:{(Backup,Security)}\\\\" + arrComputers[i] + "\\root\\CIMV2");
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTEventlogFile", "WQL",
wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
for (; !enumItems.atEnd(); enumItems.moveNext())
{
var objItem = enumItems.item();
var strBackupFile = strBackup + arrComputers[i] + "_" + TimeNow() + "_" + objItem.LogfileName + ".evt";
try { objItem.BackupEventLog(strBackupFile) }
catch(e) { a.WriteLine(TimeNowLog() + arrComputers[i] + ": " + objItem.LogfileName + " couldn't be saved"); }
try { objItem.ClearEventLog() }
catch(e) { a.WriteLine(TimeNowLog() + arrComputers[i] + ": " + objItem.LogfileName + " couldn't be cleared"); }
}
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.MoveFile("\\\\" + arrComputers[i] + "\\c$\\*.evt", "\\\\HOME\\eventlog\\");
}
a.Close();
function TimeNow()
{
d = new Date();
var strNow = "";
strNow += LeadingZero(d.getFullYear()) + "_";
strNow += LeadingZero((d.getMonth()) + 1) + "_";
strNow += LeadingZero(d.getDate()) + "_";
strNow += LeadingZero(d.getHours()) + "_";
strNow += LeadingZero(d.getMinutes()) + "_";
strNow += LeadingZero(d.getSeconds());
return(strNow);
}
function TimeNowLog()
{
d = new Date();
var strNow = "";
strNow += LeadingZero(d.getFullYear()) + "/";
strNow += LeadingZero((d.getMonth()) + 1) + "/";
strNow += LeadingZero(d.getDate()) + " ";
strNow += LeadingZero(d.getHours()) + ":";
strNow += LeadingZero(d.getMinutes()) + ":";
strNow += LeadingZero(d.getSeconds()) + " ";
return(strNow);
}
function LeadingZero(intNum)
{
if (10 > intNum)
{ intNum = "0" + intNum;}
return(intNum);
}[/more]