Delete a file using WMI (VBScript)

This code can be found in Chapter 8 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows XP Cookbook"
' ISBN: 0596007256

' This code deletes a file using WMI
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strFilePath = "<FilePath>" ' e.g. "d:\scripts\test.txt"
' ------ END CONFIGURATION ---------
set objFile = GetObject("winmgmts:\\"& strComputer & _
 "\root\cimv2:CIM_Datafile.Name='" & strFilePath & "'")
objFile.Delete
WScript.Echo "Successfully deleted file"

This code has been viewed 2444 times.

New from the creators of TechTasks.com: StatSheet.com