title: Delete Desktop contents for all the User Profiles
body: <p>Am new to vbscript and I have a task to delete all folders and files of all the user profiles under C:\Users am not an administrator but incharge of the vbscript for the team,I do not have administrator access to delete user profiles, multiple people would log in to the same desktop in all the shifts hence multiple user profiles will be created, the folder and files in desktop of all user profiles which are 30 days old should be deleted.</p>
  
  <p>I have tried the below script found from different sources in google with the help of the Admin elevated privilegestried to run the script but still it is throwing permission denied for all user profiles folder.</p>
  
  <pre><code>On Error Resume Next
  Dim objFSo, objFolder, objSubFolder, objFile,StrD,colSubFolders
  Set objFSo = CreateObject("Scripting.FileSystemObject")
  Set wshNetwork = CreateObject("WScript.Shell")
  
  Set objFolder = objFSO.GetFolder("C:\Users\")
  Set colSubFolders = objFolder.SubFolders
  For Each objSubFolder in colSubFolders
  strD = objSubFolder
  If (objFSo.FolderExists(objSubFolder)=True) Then
  wshNetwork.Run "CMD /L TAKEOWN /F """ &amp; strD &amp; """ /R/D Y",1,True
  For Each objFile In objFSo.GetFolder(strD).Files
  If objFile.DateLastModified &lt; (Now() - 30) Then
      objFSo.DeleteFile objFile.Path,True
  End If
  Next
  </code></pre>
  
  <p>The logic did not work and it throws Permission Denied 800A0046 in the second loop <code>For Each objFile In objFSo.GetFolder(strD).Files</code> which will not loop through any files under User Profile, could you please help me in the script which is the best way to delete Folders and files from desktop for all User profiles</p>