Windows XP Problem with deleting files through WMI

Joined
Jul 18, 2005
Messages
1
Reaction score
0
I want to make a script that deletes the folder and all the files in it. The script i am using is:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = 'c:\\Documents and Settings\arehman\Desktop\test'")

For Each objFolder in colFolders
errResults = objFolder.Delete
Next

when i run the bat file with the above script a screen flashes on the monitor and nothing else happens. I also restarted the services. Same problem.
Someone please tell me where did i go wrong.
Thanks
 
Joined
Aug 31, 2005
Messages
1
Reaction score
0
Well, I'm looking for the same thing. But some pointers. Run in a cmd window using cscript and you will get a persistent execution. You can code in echo markers to locate where you are when bad things happen. Or download and enable the debugger (search Microsoft).

What I need is to delete an entire tree of files and folders, and I can't seem to get the regular expressions to work in the way I think they should (starting with the same script you have, BTW). I see a lot of questions about this. Surely someone (please!) has faced this and solved it. Or is there a "force" mechanism to force deleting a folder even if it has content?

Best regards

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top