0

我正在尝试使用 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”没有脚本引擎。我可以让脚本检查共享是否在线,如果没有则跳到下一个?

4

1 回答 1

0

您的问题是您在第一个完成之前运行 sub SynchronizeOfflineFiles 。然后,当它发生时,你有 Set objFolderPath = nothing。

您可以在前一个完成后使用不同的参数运行 sub,也可以使用不同的 objFolderPath 编写多个版本的 SynchronizeOfflineFiles。

于 2018-06-07T07:43:09.960 回答