none
Remove One Folder from Offline Files Cache

    Domanda

  • I am not sure where to place this question, but I will start here.  The problem is that on Windows 7 (Ent) I have several servers and shares in the "Offline Files Folder" that I don't want there anymore; they are either folders I used temporarily or no longer exist. In the folder, I can right-click a computer and "Delete Offline Copy", and it will respond "Completed Deleting Offline Copies", but the computer and share are still listed.  I want to make some of those computers go away from my cache completely, so that they are no longer listed and no longer post to the offline files event log when they connect or disconnect.

    I know that clearing the CSC cache with the registry key "formatdatabase" is an option, but that would mean clearing out the entire CSC cache, which will be highly inconvenient to reload, and with multiple users constitutes possible data loss. 

    Furthermore, I see that the Win32_OfflineFilesCache has a method called "deleteItems", but I cannot get it to work correctly in vbscript.  Here is my code, which results in "SWbemObjectEx: Type mismatch".

    dim uiResult
    Set objWMILocator = WScript.CreateObject("WbemScripting.SWbemLocator")
    Set objWMIServices = objWMILocator.ConnectServer("localHost", "root\cimv2")
    Set objCache = objWMIServices.Get("Win32_OfflineFilesCache=@")
    uiResult = objCache.pin("\\server\share",&H00000010)

    So I would be happy with one of two things: either a working example of using Win32_OfflineFilesCache.DeleteItems, or another way to remove a certain server/share from the Offline Files Cache in Windows 7.  Thanks in advance for any help or guidance you give.

    • Modificato rpseekell lunedì 14 maggio 2012 14:08
    lunedì 14 maggio 2012 14:07

Risposte

  • The folks at Scripting Guys Forum helped me find a way using PowerShell.  It is something like this:

    $cs = Get-WmiObject -List win32_offlineFilesCache -ComputerName $compName
    $cs.deleteItems($item2Delete,2147483648)
    If this code is run as administrator, then the "flags" in the deleteItems method will force the delete regardless of access rights.
    • Contrassegnato come risposta rpseekell venerdì 25 maggio 2012 19:47
    venerdì 25 maggio 2012 19:47

Tutte le risposte

  • Hi,

    According to your description, I suggest to contact Script Forum to check if your VBscript has any problem:

    The Official Scripting Guys Forum! Forum

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. 

    Thank you for your understanding.

    Regards,

    Leo   Huang


    Leo Huang

    TechNet Community Support

    mercoledì 16 maggio 2012 02:26
    Moderatore
  • OK, well put aside the vbscript for now.  Is there a way to remove a server/share from offline files so that it doesn't show in "Offline Files Folder", doesn't try to sync, and doesn't report in the Offline Files event log?  It seems that using the formatdatabase registry key to reset the cache might do it, but I see this as a "nuclear option" and a last resort.
    mercoledì 16 maggio 2012 11:52
  • The folks at Scripting Guys Forum helped me find a way using PowerShell.  It is something like this:

    $cs = Get-WmiObject -List win32_offlineFilesCache -ComputerName $compName
    $cs.deleteItems($item2Delete,2147483648)
    If this code is run as administrator, then the "flags" in the deleteItems method will force the delete regardless of access rights.
    • Contrassegnato come risposta rpseekell venerdì 25 maggio 2012 19:47
    venerdì 25 maggio 2012 19:47
  • If you want to use vbs there are script below:

    Dim uiResult
    Dim strComputer, objWMIService, colItems, objItem, blnFlag
    Dim myArray(0)
    
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\localhost\root\cimv2")
    Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_OfflineFilesItem where " &_
    "NOT ItemName LIKE '%server_name1%' AND NOT ItemName LIKE '%server_name2%' AND ItemType = 3 ")
    
    For Each objItem In colItems
        myArray(0) = objItem.ItemName
        WScript.Echo objItem.ItemName
        Set objWMILocator = WScript.CreateObject("WbemScripting.SWbemLocator")
        Set objWMIServices = objWMILocator.ConnectServer("localHost", "root\cimv2")
        Set objCache = objWMIServices.Get("Win32_OfflineFilesCache=@")
        uiResult = objCache.Unpin(myArray,&H00000020,TRUE)
        uiResult = objCache.DeleteItems(myArray,&H00000004)
    Next

    There is neccessary to define servers you are currently using in query replacing server_name1 and server_name2 or add next one. All other files will be deleted.

    • Proposto come risposta Mateusz Ples mercoledì 8 maggio 2013 09:40
    • Proposta come risposta annullata Mateusz Ples mercoledì 8 maggio 2013 09:40
    • Proposto come risposta Mateusz Ples mercoledì 8 maggio 2013 10:08
    mercoledì 8 maggio 2013 08:54