Answered by:

Deleting a folder in all users profiles

Question

I have a VBScript that recursively searches all user profiles and deletes a folder that I specify, for the sake of it lets call it Example. The script works fine in XP but won't work in Windows 7.

In XP, it will go to C:\Documents and Settings\ and scan through all user profiles and delete the Example folder which is exactly what I want.

In Windows 7, it goes to C:\Users and checks C:\Users\Administrator and then exits without scanning any other profile. The strange this is, if I change the script to scan c:\temp and add profiles then it scans through them and deletes Example as required.

Is there a trick to recursively scanning through c:\users? Below is the script that I am using (not my work, I am not capable of scripting such things) with the rootFolder set for Windows 7 C:\Users

'Deletes all folders in 'rootFolder' that are called 'folderSpec'
Sub deleteAllFolders(rootFolder)
set folderCollection = fs.GetFolder(rootFolder)
wscript.echo "Starting at folder: " & rootFolder
for each subFolder in folderCollection.subFolders
wscript.echo "Checking folder: " & subfolder.path
RecursiveSearchAndDelete(subFolder.path)
next
end sub

Answers

As to run the command in Powershell was a single line, I ran it from a batch file. The batch file simply said Powershell and then the command and it ran without any problem or signed certificate etc.... was a very easy by-pass in the end but took me a long
time to get to it.

... I have a VBScript that recursively searches all user profiles and deletes a folder that I specify, for the sake of it lets call it Example. The script works fine in XP but won't work in Windows 7.

In XP, it will go to C:\Documents and Settings\ and scan through all user profiles and delete the Example folder which is exactly what I want.

In Windows 7, it goes to C:\Users and checks C:\Users\Administrator and then exits without scanning any other profile. The strange this is, if I change the script to scan c:\temp and add profiles then it scans through them and deletes Example as required
...

Hi,

Based on the above script settings, it is capable of deleting C:\Users\<profile>\Example. One probable cause for not producing the expected result could be due to UAC issue. To verify, please try this on one machine:

Click Start menu.

Click All Programs followed by Accessories.

Right click on Command Prompt and left click on Run as administrator.

Run the script to verify that it is working as per normal. If it is working, it means that you need to execute this script using elevated rights. One suggestion is to run it as a scheduled task.

As to run the command in Powershell was a single line, I ran it from a batch file. The batch file simply said Powershell and then the command and it ran without any problem or signed certificate etc.... was a very easy by-pass in the end but took me a long
time to get to it.

Microsoft is conducting an online survey to understand your opinion of the Technet Web site. If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.