【问题标题】:VBS Sync Center Synchronize offline filesVBS 同步中心 同步离线文件
【发布时间】:2018-06-06 21:44:38
【问题描述】:

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

【问题讨论】:

    标签: vbscript center synchronisation


    【解决方案1】:

    您的问题是您在第一个完成之前运行 sub SynchronizeOfflineFiles 。然后,当它执行时,您将设置 objFolderPath = nothing。

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

    【讨论】:

    • 奇怪的是,如果我用不同的 objFolderPath 编写多个版本的 SynchronizeOfflineFiles,它不会同步我询问的唯一路径。但是,如果我像以前一样将三个路径放在一起,它将同步一个路径。但其他两条路径的状态是:同步挂起。当第一条路径同步时,它们将失败。当我按下 Sync Center 中的 Sync All 按钮时,它将同时同步所有路径而不会出错。使用 vbs 脚本可以做到这一点吗?
    猜你喜欢
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多