Home
%3CLINGO-SUB%20id%3D%22lingo-sub-423374%22%20slang%3D%22en-US%22%3ECscSync.vbs%20%E2%80%93%20Sync%20a%20particular%20UNC%20path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-423374%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20TECHNET%20on%20Apr%2026%2C%202007%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20THIS%20CODE%20AND%20INFORMATION%20IS%20PROVIDED%20%22AS%20IS%22%20WITHOUT%20WARRANTY%20OF%20%3CBR%20%2F%3E%20'%20ANY%20KIND%2C%20EITHER%20EXPRESSED%20OR%20IMPLIED%2C%20INCLUDING%20BUT%20NOT%20LIMITED%20TO%20%3CBR%20%2F%3E%20'%20THE%20IMPLIED%20WARRANTIES%20OF%20MERCHANTABILITY%20AND%2FOR%20FITNESS%20FOR%20A%20%3CBR%20%2F%3E%20'%20PARTICULAR%20PURPOSE.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Copyright%20(c)%20Microsoft%20Corporation.%20All%20rights%20reserved.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Usage%3A%20CscSync.vbs%20%2FItemPath%3A%3CPATH%3E%20%5B%2FDirection%3Ain%7Cout%7Cinout%5D%20%5B%2FPinNewFiles%3A1%3A0%5D%20%5B%2FConflicts%3Alocal%7Cremote%7Clatest%5D%20%5B%2FMachine%3Avalue%5D%20%5B%2FUser%3Avalue%5D%20%5B%2FPassword%3Avalue%5D%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Demonstrates%20how%20to%20sync%20an%20item%20or%20tree%20in%20the%20Offline%20Files%20cache.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20const%20cComputerName%20%3D%20%22LocalHost%22%20%3CBR%20%2F%3E%20const%20cWMINamespace%20%3D%20%22root%5Ccimv2%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Process%20commandline%20arguments%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20strItemPath%20%3D%20WScript.Arguments.Named(%22ItemPath%22)%20%3CBR%20%2F%3E%20if%20Len(strItemPath)%20%3D%200%20Then%20%3CBR%20%2F%3E%20Wscript.Echo%20%22ItemPath%20parameter%20required%22%20%3CBR%20%2F%3E%20Err.Raise%20449%20'%20%22argument%20not%20optional%22%20error%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strComputerName%20%3D%20WScript.Arguments.Named(%22Machine%22)%20%3CBR%20%2F%3E%20If%20Len(strComputerName)%20%3D%200%20Then%20strComputerName%20%3D%20cComputerName%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strUserID%20%3D%20WScript.Arguments.Named(%22User%22)%20%3CBR%20%2F%3E%20If%20Len(strUserID)%20%3D%200%20Then%20strUserID%20%3D%20%22%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strPassword%20%3D%20WScript.Arguments.Named(%22Password%22)%20%3CBR%20%2F%3E%20If%20Len(strPassword)%20%3D%200%20Then%20strPassword%20%3D%20%22%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Sync%20control%20flags%20from%20Win32_OfflineFilesCache.Synchronize%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20const%20fFillSparse%20%3D%20%26amp%3BH00000001%20%3CBR%20%2F%3E%20const%20fSyncIn%20%3D%20%26amp%3BH00000002%20%3CBR%20%2F%3E%20const%20fSyncOut%20%3D%20%26amp%3BH00000004%20%3CBR%20%2F%3E%20const%20fPinNewFiles%20%3D%20%26amp%3BH00000008%20%3CBR%20%2F%3E%20const%20fPinLinkTargets%20%3D%20%26amp%3BH00000010%20%3CBR%20%2F%3E%20const%20fPinForUser%20%3D%20%26amp%3BH00000020%20%3CBR%20%2F%3E%20const%20fPinForUser_Policy%20%3D%20%26amp%3BH00000040%20%3CBR%20%2F%3E%20const%20fPinForAll%20%3D%20%26amp%3BH00000080%20%3CBR%20%2F%3E%20const%20fLowPriority%20%3D%20%26amp%3BH00000200%20%3CBR%20%2F%3E%20const%20fAsyncProgress%20%3D%20%26amp%3BH00000400%20%3CBR%20%2F%3E%20const%20fInteractive%20%3D%20%26amp%3BH00000800%20%3CBR%20%2F%3E%20const%20fConsole%20%3D%20%26amp%3BH00001000%20%3CBR%20%2F%3E%20const%20fSkipSuspendedDirs%20%3D%20%26amp%3BH00002000%20%3CBR%20%2F%3E%20const%20fBackground%20%3D%20%26amp%3BH00010000%20%3CBR%20%2F%3E%20const%20fCrKeepLocal%20%3D%20%26amp%3BH10000000%20%3CBR%20%2F%3E%20const%20fCrKeepRemote%20%3D%20%26amp%3BH20000000%20%3CBR%20%2F%3E%20const%20fCrKeepLatest%20%3D%20%26amp%3BH30000000%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20const%20wbemFlagSendStatus%20%3D%20%26amp%3BH00000080%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20fSyncIn%20%2B%20_%20%3CBR%20%2F%3E%20fSyncOut%20%2B%20_%20%3CBR%20%2F%3E%20fPinNewFiles%20%2B%20_%20%3CBR%20%2F%3E%20fPinForUser%20%2B%20_%20%3CBR%20%2F%3E%20fConsole%20%2B%20_%20%3CBR%20%2F%3E%20fInteractive%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strDirection%20%3D%20WScript.Arguments.Named(%22Direction%22)%20%3CBR%20%2F%3E%20If%20Len(strDirection)%20%26lt%3B%26gt%3B%200%20Then%20%3CBR%20%2F%3E%20if%20LCase(strDirection)%20%3D%20%22in%22%20Then%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20SyncControlFlags%20-%20fSyncOut%20%3CBR%20%2F%3E%20Elseif%20LCase(strDirection)%20%3D%20%22out%22%20Then%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20SyncControlFlags%20-%20fSyncIn%20%3CBR%20%2F%3E%20Elseif%20LCase(strDirection)%20%3D%20%22inout%22%20Then%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Flags%20already%20configured%20for%20in%2Fout%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20Else%20%3CBR%20%2F%3E%20Wscript.Echo%20%22Invalid%20direction%20value%20%5B%22%20%26amp%3B%20strDirection%20%26amp%3B%20%22%5D%22%20%3CBR%20%2F%3E%20Err.Raise%20507%20'%20%22an%20exception%20occured%22%20error%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strPinNewFiles%20%3D%20WScript.Arguments.Named(%22PinNewFiles%22)%20%3CBR%20%2F%3E%20If%20Len(strPinNewFiles)%20%26lt%3B%26gt%3B%200%20And%20strPinNewFiles%20%3D%20%220%22%20Then%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20SyncControlFlags%20-%20fPinNewFiles%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20strConflicts%20%3D%20WScript.Arguments.Named(%22Conflicts%22)%20%3CBR%20%2F%3E%20If%20Len(strConflicts)%20%26lt%3B%26gt%3B%200%20Then%20%3CBR%20%2F%3E%20If%20LCase(strConflicts)%20%3D%20%22local%22%20Then%20%3CBR%20%2F%3E%20SyncControlflags%20%3D%20SyncControlFlags%20%2B%20fCrKeepLocal%20%3CBR%20%2F%3E%20Elseif%20LCase(strConflicts)%20%3D%20%22remote%22%20Then%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20SyncControlFlags%20%2B%20fCrKeepRemote%20%3CBR%20%2F%3E%20Elseif%20LCase(strConflicts)%20%3D%20%22latest%22%20Then%20%3CBR%20%2F%3E%20SyncControlFlags%20%3D%20SyncControlFlags%20%2B%20fCrKeepLatest%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20End%20if%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Set%20objWMILocator%20%3D%20WScript.CreateObject(%22WbemScripting.SWbemLocator%22)%20%3CBR%20%2F%3E%20Set%20objWMIServices%20%3D%20objWMILocator.ConnectServer(strComputerName%2C%20_%20%3CBR%20%2F%3E%20cWMINameSpace%2C%20_%20%3CBR%20%2F%3E%20strUserID%2C%20_%20%3CBR%20%2F%3E%20strPassword)%20%3CBR%20%2F%3E%20Set%20objCache%20%3D%20objWMIServices.Get(%22Win32_OfflineFilesCache%3D%40%22)%20%3CBR%20%2F%3E%20Set%20objParams%20%3D%20objCache.Methods_(%22Synchronize%22).InParameters.SpawnInstance_%20%3CBR%20%2F%3E%20Set%20objSink%20%3D%20WScript.CreateObject(%22WbemScripting.SWbemSink%22%2C%20%22SINK_%22)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Set%20up%20the%20API%20arguments%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20Dim%20ItemPaths(0)%20%3CBR%20%2F%3E%20ItemPaths(0)%20%3D%20strItemPath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20objParams.Paths%20%3D%20ItemPaths%20%3CBR%20%2F%3E%20objParams.Flags%20%3D%20SyncControlFlags%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Execute%20the%20sync%20action%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20objWMIServices.ExecMethodAsync%20objSink%2C%20%22Win32_OfflineFilesCache%22%2C%20%22Synchronize%22%2C%20objParams%2C%20wbemFlagSendStatus%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Loop%20until%20we%20receive%20an%20OnCompleted%20event%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20bDone%20%3D%20False%20%3CBR%20%2F%3E%20While%20Not%20bDone%20%3CBR%20%2F%3E%20wscript.sleep%201000%20%3CBR%20%2F%3E%20Wend%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Sub%20SINK_OnProgress(UpperBound%2C%20Current%2C%20Message%2C%20objContext)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20DIM%20PART_REASON%2C%20PART_RESULT%2C%20PART_RESULTMSG%2C%20PART_PATH%20%3CBR%20%2F%3E%20DIM%20REASON_BEGIN%2C%20REASON_END%2C%20REASON_ITEMBEGIN%2C%20REASON_ITEMRESULT%20%3CBR%20%2F%3E%20DIM%20Reasons(3)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20The%20message%20is%20composed%20as%20follows%3A%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CREASON%3E%3A%3CRESULT%3E%3A%3CRESULT%20msg%3D%22%22%3E%3A%3CPATH%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CREASON%3E%20%3CBR%20%2F%3E%20'%20Integer%20indicates%20reason%20for%20progress%20callback.%20%3CBR%20%2F%3E%20'%20Values%20are%3A%20%3CBR%20%2F%3E%20'%200%20-%20%22Begin%22%20overall%20operation%20%3CBR%20%2F%3E%20'%201%20-%20%22End%22%20overall%20operation%20%3CBR%20%2F%3E%20'%202%20-%20%22Begin%20Item%22%20operation%20%3CBR%20%2F%3E%20'%203%20-%20%22Item%20result%22%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CRESULT%3E%20%3CBR%20%2F%3E%20'%20Integer%20result%20code%3B%20HRESULT.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CRESULT%20msg%3D%22%22%3E%20%3CBR%20%2F%3E%20'%20Text%20describing%20the%20result.%20In%20most%20cases%20this%20is%20translated%20using%20%3CBR%20%2F%3E%20'%20the%20Win32%20function%20FormatMessage.%20In%20some%20cases%20a%20more%20descriptive%20%3CBR%20%2F%3E%20'%20message%20is%20provided%20that%20is%20better%20aligned%20with%20Offline%20Files.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20%3CPATH%3E%20%3CBR%20%2F%3E%20'%20UNC%20path%20string%20associated%20with%20the%20progress%20notifcation.%20This%20is%20%3CBR%20%2F%3E%20'%20empty%20for%20the%20%22Begin%22%20and%20%22End%22%20notifications.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Define%20indexes%20of%20the%20various%20parts%20in%20the%20message.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20PART_REASON%20%3D%200%20%3CBR%20%2F%3E%20PART_RESULT%20%3D%201%20%3CBR%20%2F%3E%20PART_RESULTMSG%20%3D%202%20%3CBR%20%2F%3E%20PART_PATH%20%3D%203%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20The%20reason%20codes%20present%20in%20the%20%3CREASON%3E%20part.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20REASON_BEGIN%20%3D%200%20%3CBR%20%2F%3E%20REASON_END%20%3D%201%20%3CBR%20%2F%3E%20REASON_ITEMBEGIN%20%3D%202%20%3CBR%20%2F%3E%20REASON_ITEMRESULT%20%3D%203%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20split%20the%20message%20into%20the%204%20parts%20and%20extract%20those%20parts.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20Parts%20%3D%20Split(Message%2C%20%22%3A%22%2C%20-1%2C%201)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Reason%20%3D%20CInt(Parts(PART_REASON))%20%3CBR%20%2F%3E%20Path%20%3D%20Parts(PART_PATH)%20%3CBR%20%2F%3E%20Result%20%3D%20CLng(Parts(PART_RESULT))%20%3CBR%20%2F%3E%20ResultMsg%20%3D%20Parts(PART_RESULTMSG)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Select%20Case%20Reason%20%3CBR%20%2F%3E%20Case%20REASON_ITEMRESULT%20%3CBR%20%2F%3E%20WScript.Echo%20Path%20%3CBR%20%2F%3E%20if%200%20%26lt%3B%26gt%3B%20Result%20then%20%3CBR%20%2F%3E%20Wscript.Echo%20%22%20Error%3A%20%22%20%26amp%3B%20Hex(Result)%20%26amp%3B%20%22%20%22%20%26amp%3B%20ResultMsg%20%3CBR%20%2F%3E%20end%20if%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Case%20REASON_END%20%3CBR%20%2F%3E%20if%200%20%26lt%3B%26gt%3B%20Result%20then%20%3CBR%20%2F%3E%20Wscript.Echo%20%22Error%3A%20%22%20%26amp%3B%20Hex(Result)%20%26amp%3B%20%22%20%22%20%26amp%3B%20ResultMsg%20%3CBR%20%2F%3E%20end%20if%20%3CBR%20%2F%3E%20End%20Select%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20End%20Sub%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20'%20Called%20when%20the%20operation%20is%20complete.%20%3CBR%20%2F%3E%20'%20%3CBR%20%2F%3E%20Sub%20SINK_OnCompleted(HResult%2C%20objLastError%2C%20objContext)%20%3CBR%20%2F%3E%20bDone%20%3D%20True%20%3CBR%20%2F%3E%20End%20Sub%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3C%2FREASON%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-423374%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Apr%2026%2C%202007%20''%20THIS%20CODE%20AND%20INFORMATION%20IS%20PROVIDED%20%22AS%20IS%22%20WITHOUT%20WARRANTY%20OF'%20ANY%20KIND%2C%20EITHER%20EXPRESSED%20OR%20IMPLIED%2C%20INCLUDING%20BUT%20NOT%20LIMITED%20TO'%20THE%20IMPLIED%20WARRANTIES%20OF%20MERCHANTABILITY%20AND%2FOR%20FITNESS%20FOR%20A'%20PARTICULAR%20PURPOSE.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-423374%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPages%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FPATH%3E%3C%2FRESULT%3E%3C%2FRESULT%3E%3C%2FREASON%3E%3C%2FPATH%3E%3C%2FRESULT%3E%3C%2FRESULT%3E%3C%2FREASON%3E%3C%2FPATH%3E%3C%2FLINGO-BODY%3E
Not applicable
First published on TECHNET on Apr 26, 2007
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
'
' Usage: CscSync.vbs /ItemPath:<path> [/Direction:in|out|inout] [/PinNewFiles:1:0] [/Conflicts:local|remote|latest] [/Machine:value] [/User:value] [/Password:value]
'
'
' Demonstrates how to sync an item or tree in the Offline Files cache.
'
'

const cComputerName = "LocalHost"
const cWMINamespace = "root\cimv2"


'
' Process commandline arguments
'
strItemPath = WScript.Arguments.Named("ItemPath")
if Len(strItemPath) = 0 Then
Wscript.Echo "ItemPath parameter required"
Err.Raise 449 ' "argument not optional" error
End if

strComputerName = WScript.Arguments.Named("Machine")
If Len(strComputerName) = 0 Then strComputerName = cComputerName

strUserID = WScript.Arguments.Named("User")
If Len(strUserID) = 0 Then strUserID = ""

strPassword = WScript.Arguments.Named("Password")
If Len(strPassword) = 0 Then strPassword = ""

'
' Sync control flags from Win32_OfflineFilesCache.Synchronize
'
const fFillSparse = &H00000001
const fSyncIn = &H00000002
const fSyncOut = &H00000004
const fPinNewFiles = &H00000008
const fPinLinkTargets = &H00000010
const fPinForUser = &H00000020
const fPinForUser_Policy = &H00000040
const fPinForAll = &H00000080
const fLowPriority = &H00000200
const fAsyncProgress = &H00000400
const fInteractive = &H00000800
const fConsole = &H00001000
const fSkipSuspendedDirs = &H00002000
const fBackground = &H00010000
const fCrKeepLocal = &H10000000
const fCrKeepRemote = &H20000000
const fCrKeepLatest = &H30000000

const wbemFlagSendStatus = &H00000080

SyncControlFlags = fSyncIn + _
fSyncOut + _
fPinNewFiles + _
fPinForUser + _
fConsole + _
fInteractive

strDirection = WScript.Arguments.Named("Direction")
If Len(strDirection) <> 0 Then
if LCase(strDirection) = "in" Then
SyncControlFlags = SyncControlFlags - fSyncOut
Elseif LCase(strDirection) = "out" Then
SyncControlFlags = SyncControlFlags - fSyncIn
Elseif LCase(strDirection) = "inout" Then
'
' Flags already configured for in/out
'
Else
Wscript.Echo "Invalid direction value [" & strDirection & "]"
Err.Raise 507 ' "an exception occured" error
End if
End if

strPinNewFiles = WScript.Arguments.Named("PinNewFiles")
If Len(strPinNewFiles) <> 0 And strPinNewFiles = "0" Then
SyncControlFlags = SyncControlFlags - fPinNewFiles
End if

strConflicts = WScript.Arguments.Named("Conflicts")
If Len(strConflicts) <> 0 Then
If LCase(strConflicts) = "local" Then
SyncControlflags = SyncControlFlags + fCrKeepLocal
Elseif LCase(strConflicts) = "remote" Then
SyncControlFlags = SyncControlFlags + fCrKeepRemote
Elseif LCase(strConflicts) = "latest" Then
SyncControlFlags = SyncControlFlags + fCrKeepLatest
End if
End if

Set objWMILocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objWMIServices = objWMILocator.ConnectServer(strComputerName, _
cWMINameSpace, _
strUserID, _
strPassword)
Set objCache = objWMIServices.Get("Win32_OfflineFilesCache=@")
Set objParams = objCache.Methods_("Synchronize").InParameters.SpawnInstance_
Set objSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

'
' Set up the API arguments
'
Dim ItemPaths(0)
ItemPaths(0) = strItemPath

objParams.Paths = ItemPaths
objParams.Flags = SyncControlFlags

'
' Execute the sync action
'
objWMIServices.ExecMethodAsync objSink, "Win32_OfflineFilesCache", "Synchronize", objParams, wbemFlagSendStatus

'
' Loop until we receive an OnCompleted event
'
bDone = False
While Not bDone
wscript.sleep 1000
Wend


Sub SINK_OnProgress(UpperBound, Current, Message, objContext)

DIM PART_REASON, PART_RESULT, PART_RESULTMSG, PART_PATH
DIM REASON_BEGIN, REASON_END, REASON_ITEMBEGIN, REASON_ITEMRESULT
DIM Reasons(3)

'
' The message is composed as follows:
'
' <reason>:<result>:<result msg>:<path>
'
' <reason>
' Integer indicates reason for progress callback.
' Values are:
' 0 - "Begin" overall operation
' 1 - "End" overall operation
' 2 - "Begin Item" operation
' 3 - "Item result"
'
' <result>
' Integer result code; HRESULT.
'
' <result msg>
' Text describing the result. In most cases this is translated using
' the Win32 function FormatMessage. In some cases a more descriptive
' message is provided that is better aligned with Offline Files.
'
' <path>
' UNC path string associated with the progress notifcation. This is
' empty for the "Begin" and "End" notifications.
'

'
' Define indexes of the various parts in the message.
'
PART_REASON = 0
PART_RESULT = 1
PART_RESULTMSG = 2
PART_PATH = 3

'
' The reason codes present in the <reason> part.
'
REASON_BEGIN = 0
REASON_END = 1
REASON_ITEMBEGIN = 2
REASON_ITEMRESULT = 3

'
' split the message into the 4 parts and extract those parts.
'
Parts = Split(Message, ":", -1, 1)

Reason = CInt(Parts(PART_REASON))
Path = Parts(PART_PATH)
Result = CLng(Parts(PART_RESULT))
ResultMsg = Parts(PART_RESULTMSG)

Select Case Reason
Case REASON_ITEMRESULT
WScript.Echo Path
if 0 <> Result then
Wscript.Echo " Error: " & Hex(Result) & " " & ResultMsg
end if

Case REASON_END
if 0 <> Result then
Wscript.Echo "Error: " & Hex(Result) & " " & ResultMsg
end if
End Select

End Sub

'
' Called when the operation is complete.
'
Sub SINK_OnCompleted(HResult, objLastError, objContext)
bDone = True
End Sub