发信人: williamlong(蓝色月光)
整理人: williamlong(2001-12-17 14:31:21), 站内信件
|
下面是我用VB写的一个自动恢复主页的程序 , 时间和目录都可以在INI文件中设置,此程序需要一个叫 inifile.dll 的文件 , 用VB6编译修改 。
Option Explicit
Dim MainDir, BackupDir
Dim CheckTime, Start, Finish, TotalTime, ErrMsg
Function FileExists(ByVal Path) As Integer
On Error GoTo DIR_ERROR
Dim s
s = Dir(Path)
If Trim(s) = Empty Then
Exit Function
End If
FileExists = True
Exit Function
DIR_ERROR:
Exit Function
End Function
' 检查文件
Sub CheckFile(ByVal CheckFileName)
On Error Resume Next
Dim fs, f1, f2, s1, s2
s1 = "0"
s2 = "1"
Set fs = CreateObject("Scripting.FileSystemObject")
If FileExists(MainDir + CheckFileName) Then
Set f1 = fs.GetFile(MainDir + CheckFileName)
Set f2 = fs.GetFile(BackupDir + CheckFileName)
s1 = f1.DateLastModified
s2 = f2.DateLastModified
End If
If s1 <> s2 Then
fs.CopyFile BackupDir + CheckFileName, MainDir, True
End If
End Sub
Private Sub Form_Load()
On Error Resume Next
If Right(App.Path, 1) = "\" Then
IniFile.IniFileName = App.Path & "watcher.ini"
Else
IniFile.IniFileName = App.Path & "\" & "watcher.ini"
End If
MainDir = IniFile.GetSet("watcher", "MainDir", "Z:\")
BackupDir = IniFile.GetSet("watcher", "BackupDir", "Z:\")
CheckTime = IniFile.GetSet("watcher", "CheckTime", 10) ' 设置暂停时间。
If CheckTime < 64 Then
CheckTime = CheckTime * 1000
SysTimer.Interval = CheckTime
End If
' 只运行一次
If App.PrevInstance Then
ErrMsg = MsgBox("系统已经有一个程序正在运行中!", vbCritical, "系统错误")
End
End If
' 检查目录是否存在
If Not FileExists(MainDir) Then
ErrMsg = MsgBox(MainDir + "目录没有找到,系统终止!", vbCritical, "系统错误")
End
End If
If Not FileExists(BackupDir) Then
ErrMsg = MsgBox(BackupDir + "目录没有找到,系统终止!", vbCritical, "系统错误")
End
End If
' 开始定时检查文件
' 开始遍历目录内所有文件
End Sub
Private Sub SysTimer_Timer()
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(BackupDir)
Set fc = f.Files
For Each f1 In fc
CheckFile (f1.Name)
Next
End Sub
【 在 vicolan 的大作中提到:】
:象白金汉宫的主页一被黑掉的几秒钟内就可以马上自动恢复了!是用什么软件的?
:......
----
|
|