我正在尝试使用 VBScript 同步脱机文件。我编辑了下面的代码以同步三个路径:
Set wshShell = CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
strPathProfile = "\\SRV01\Path1$\" & strUserName
strPathHome = "\\SRV01\Path2$\" & strUserName
strPathShared = "\\SRV01\Path3$"
SynchronizeOfflineFiles strPathProfile
SynchronizeOfflineFiles strPathShared
SynchronizeOfflineFiles strPathHome
Sub SynchronizeOfflineFiles(strSyncPath)
Dim objShell
Dim objFolderPath
Set objShell = CreateObject("shell.application")
Set objFolderPath = objShell.NameSpace(strSyncPath)
If (not objFolderPath is nothing) then
objFolderPath.Synchronize
End If
Set objFolderPath = nothing
Set objShell = nothing
End Sub
我唯一的问题是同步中心会一一同步路径,结果其中两个会失败。顶部的路径(在本例中为 strPathProfile)将成功。因此,如果我将顺序更改为例如:
SynchronizeOfflineFiles strPathHome
SynchronizeOfflineFiles strPathShared
SynchronizeOfflineFiles strPathProfile
strPathHome 会成功,另外两个会失败。
当我使用这样的WScript.Sleep 5000
命令时:
SynchronizeOfflineFiles strPathProfile
WScript.Sleep 30000
SynchronizeOfflineFiles strPathShared
WScript.Sleep 30000
SynchronizeOfflineFiles strPathHome
它将等待其他路径同步,但我必须设置时间。是否可以等到上一次同步完成?
我还收到错误消息:当其中一个共享处于脱机状态时,文件扩展名“.vbs”没有脚本引擎。我可以让脚本检查共享是否在线,如果没有则跳到下一个?