CscRenameItem.vbs


‘ 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: CscRenameItem.vbs /OldItemPath:<path> /NewItemPath:<path> [/Machine:value] [/User:value] [/Password:value]


‘ Demonstrates how to rename an item in the Ofline Files cache.

‘   OldItemPath – UNC path of the current path to be renamed.

‘   NewItemPath – UNC path of the new path to replace the old path.

‘   If NewItemPath already exists, the operation is not performed.
‘   This operation simply schedules a rename to be performed on the next restart
‘   restart of the system.

const cComputerName = “LocalHost”
const cWMINamespace = “rootcimv2”
const cWMIClass     = “Win32_OfflineFilesCache”


‘ Process commandline arguments

strOldItemPath = WScript.Arguments.Named(“OldItemPath”)’
if Len(strOldItemPath) = 0 Then
    Wscript.Echo “OldItemPath parameter required”
    Err.Raise 449  ‘ “argument not optional” error
End if

strNewItemPath = WScript.Arguments.Named(“NewItemPath”)’
if Len(strNewItemPath) = 0 Then
    Wscript.Echo “NewItemPath 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 = “”

set objWMILocator = WScript.CreateObject(“WbemScripting.SWbemLocator”)

Set objWMIServices = objWMILocator.ConnectServer(strComputerName, _
                                                 cWMINameSpace, _
                                                 strUserID, _
                                                 strPassword)


‘ Note that Win32_OfflineFilesCache is a singleton. 

‘ Also note that while we pass “False” for the bReplace parameter, that
‘ parameter is ignored.  Existing destinations are never replaced, regardless
‘ of what we pass for the 3rd parameter.

Set objCache = objWMIServices.Get(“Win32_OfflineFilesCache=@”)
objCache.RenameItem strOldItemPath, strNewItemPath, False
WScript.Echo “item rename scheduled.  A restart of the system is necessary to apply the change.”