'/**********************************************************************/ '/* */ '/* Windows hosts files update servername rebameback */ '/* */ '/* */ '/* Change File : c:\windows\system32\drivers\etc\hosts */ '/* Change value : */ '/* 172.25.000.000 servername.host.com -> #172.25.000.000 servername.host.com */ */ '/* */ '/***********************************************************************/ '/*** 実行処理(プロファイル内容の変更) ***/ '/ オブジェクト定義 ***/ Set fso = CreateObject("Scripting.FileSystemObject") Set regEx = New RegExp '/ 変更前ファイル名の定義 Set inFile = fso.OpenTextFile("C:\WINDOWS\system32\drivers\etc\hosts") '/ 変更後ファイル名の定義 Set outFile = fso.CreateTextFile("C:\WINDOWS\system32\drivers\etc\hosts_new_entry") '/ 変更前の行の値の定義 regEx.Pattern = "172.25.000.000 servername.host.com" '/ 変更後の行の値の定義 repStr = vbCrLf & "#172.25.000.000 servername.host.com" & vbCrLf '/*** 文字列置換処理実行 ***/ Do Until inFile.AtEndOfStream tempLine = inFile.ReadLine repLine = regEx.Replace(tempLine, repStr) outFile.WriteLine repLine Loop inFile.Close outFile.Close Set fso = Nothing Set regEx = Nothing Set inFile = Nothing Set outFile = Nothing '/*** 日付数値用オブジェクト定義 ***/ Dim dtmNowDate ' 現在時刻 Dim execDate ' 現在時刻 '/ 現在時刻取得 dtmNowDate = Now() '/ 実行時刻取得+数字型生成(YYYYMMDDHHmmSS) execDateTime = Year(dtmNowDate) & Right("0" & Month(dtmNowDate), 2) & Right("0" & Day(dtmNowDate), 2) & Right("0" & Hour(dtmNowDate), 2) & Right("0" & Minute(dtmNowDate), 2) & Right("0" & Second(dtmNowDate), 2) '/*** 既存プロファイルのバックアップ移動処理実行 ***/ Set fso1 = CreateObject("Scripting.FileSystemObject") fso1.MoveFile "C:\WINDOWS\system32\drivers\etc\hosts", "C:\WINDOWS\system32\drivers\etc\hosts." & execDateTime '/*** 新規プロファイルのファイル名変更処理実行 ***/ Set fso2 = CreateObject("Scripting.FileSystemObject") Set UdpSrc = fso2.GetFile("C:\WINDOWS\system32\drivers\etc\hosts_new_entry") UdpSrc.Name="hosts" Set fso1 = Nothing Set fso2 = Nothing WScript.Quit 0