OK I have a script that I want to run as a startup script, but when I run it I get an Permission Denied error. I want to run it on my term servers so that when they reboot they will delete profiles that didn't get deleted off when users log off. I have all the profile folders that I don't want deleted are hidden.
Now i can delete the folders when i log in manually i just get the error when I run the script. I have verified that there are no locks on the files, and I have checked the permissions and I have all the correct perms.
Code:
dim colsubfolders, colSubfolders2, fso, objWMIService, objSubfolder, objFolder, strComputer
strComputer = "."
Set fso = CreateObject ("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder("M:\Documents and Settings")
Set colSubfolders = objFolder.Subfolders
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objSubfolder in colSubfolders
If Not objSubfolder.Attributes AND 2 then
objSubfolder.Delete
End If
Next
Now i can delete the folders when i log in manually i just get the error when I run the script. I have verified that there are no locks on the files, and I have checked the permissions and I have all the correct perms.