アットウィキロゴ
//設定
var FTPServer = 'ftpavsecure.ca.com';
var FTPURI = '/pub/inoculan/scaneng/';
var FName = 'fv_Linux_i386.tar';
var RegPath = 'HKLM\\SOFTWARE\\ComputerAssociates\\ScanEngine';
 
var wshell = new ActiveXObject('WScript.Shell');
var LocalDir = wshell.RegRead(RegPath+'\\Path\\Engine').replace(/\\/g,'\\\\')+'\\\\';
 
var fso = new ActiveXObject('Scripting.FileSystemObject');
var cpath = fso.getFolder('.').path;
 
//いったんdirをかける
funcWrite('open '+FTPServer+'\nanonymous\nanonymous\ncd '+FTPURI+'\ndir\nquit', 'ftpsrc1.txt');
wshell.Run('cmd /c "ftp -s:ftpsrc1.txt\>result1.txt"',0,true);
 
//dirの結果から、アップデータの行を抜き出す
var FtpBuff = funcRead('result1.txt');
var objRxp = new RegExp('\n\(.+)'+FName);
FtpBuff.match(objRxp);
RemoteLine = RegExp.$1;
if (RemoteLine==''){
	WScript.Echo('サーバにアップデータが見つかりませんでした。');
	WScript.Quit();
}
 
//前回アップデート時のFTPの行と比べる
var LatestLine = funcRead('latestsize.txt');
if (RemoteLine==LatestLine){
	WScript.Echo('アップデートの必要はありません。');
}else{
	WScript.Echo('アップデートが必要です。OK押してしばらくお待ちください。');
	//再度ftpで接続してアップデータをダウンロードして解凍
	funcWrite('open '+FTPServer+'\nanonymous\nanonymous\nbinary\nget '+FTPURI+FName+'\nquit', 'ftpsrc2.txt');
	wshell.Run('ftp -s:ftpsrc2.txt',0,true);
	wshell.Run("cmd /c rundll32.exe tar32.dll, TarCommandLine zxvf "+FName+" .\\Update\\vet.da1",0,true);
	fso.CopyFile(cpath+'\\Update\\vet.da1',LocalDir);
 
	funcWrite(RemoteLine, 'latestsize.txt');
 
	//レジストリに更新日時を書き込む
	today = new Date();
	var myDateReg = parseInt((today.getTime()+'').substr(0,10));
	wshell.RegWrite(RegPath+'\\update\\VET',myDateReg,'REG_DWORD');
 
	//eTrust Antivirus Realtime Serverサービスの再起動
	wshell.Run('NET STOP \"eTrust Antivirus Realtime Server\"',0,true);
	wshell.Run('NET START \"eTrust Antivirus Realtime Server\"',0,true);
 
	WScript.Echo('アップデートしました。');
}
 
funcDel('ftpsrc1.txt');
funcDel('result1.txt');
funcDel('ftpsrc2.txt');
funcDelDir('Update');
funcDel(FName);
WScript.Quit();
 
function funcRead(tmp){	//テキストファイルを読む
	if (fso.FileExists(cpath+'\\'+tmp)){
		var stream = fso.OpenTextFile(cpath+'\\'+tmp);
		var Buff = stream.ReadAll();
		stream.Close();
		return Buff;
	}else{
		return 0;
	}
}
 
function funcWrite(tmp1,tmp2){	//tmp1(文字列)をtmp2(ファイル)に書き込む
	f1 = fso.CreateTextFile(cpath+'\\'+tmp2);
	f1.Write(tmp1);
	f1.Close();
}
 
function funcDel(tmp){	//ファイルあれば消す
	if (fso.FileExists(cpath+'\\'+tmp)){
		fso.DeleteFile(cpath+'\\'+tmp);
	}
}
 
function funcDelDir(tmp){	//dirあれば消す
	if (fso.FolderExists(cpath+'\\'+tmp)){
		fso.DeleteFolder(cpath+'\\'+tmp);
	}
}
最終更新:2010年01月02日 08:44