Sponsored Links

Login Form






Lost Password?

Syndicate

Home
Advanced File Delete Script PDF Print E-mail
User Rating: / 1
PoorBest 
Written by Cheyenne Harden   

I saw a Power Shell script recently and it showed how to delete all files recursively for a HD.
Well, I really don't know Power Script and I don't want to change from VBScript.
So, I figured that I should make a script in VBScript that could do the same thing.
This script could be useful to remove .mp3 files or the like from your file server.
WARNING!!! YOU CAN DELETE IMPORTANT SYSTEM FILES IF YOU ARE NOT CAREFUL!!!

So, go ahead and run this on you Domain Controller!!! Just Kidding!!!

----------COPY EVERYTHING BELOW THIS LINE----------

'Script to delete files via name and/or file extension
'The script will search the local HD and delete all files with the same name and/or extension.
'Created by Cheyenne Harden October 27 2006

On Error Resume Next
strComputer = "."
strFileName = inputbox("Enter the name of the file you would like to delete!" & vbCrLf & "Do NOT type in the extension.")
strFileExtension = inputbox("Enter the file extension. Without the " & "'.'")

If strFileName > "" Then
 If strFileExtension > "" Then
  DeleteFileExt()
  
 Else
  DeleteFileName()
 End If

ElseIf strFileExtension > "" Then
 DeleteExtension()
 
Else
 Wscript.Echo "No File Name Or Extension Entered"
 Wscript.Quit

End If


Sub DeleteExtension()

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where Extension =  '" & strFileExtension & "'")

For Each objFile in colFiles
 errResults = objFile.Delete
Next
End Sub

Wscript.Echo "Files Deleted"

Sub DeleteFileExt()

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where FileName = '" & strFileName & "' and Extension =  '" & strFileExtension & "'")

For Each objFile in colFiles
 errResults = objFile.Delete
Next
End Sub

Sub DeleteFileName()

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where FileName = '" & strFileName & "'")

For Each objFile in colFiles
 errResults = objFile.Delete
Next
End Sub

 

 

 


----------COPY EVERYTHING ABOVE THIS LINE----------

 

 

PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR SCRIPT!!!

To make this script work you will need one things!


1. You will need to have Admin privlidges on the target computer.

This information is provided "AS IS" with no warranties expressed or implied.

Comments
Add NewSearch
Geneva DeCaprio - Sr Technical Recruiter   | 59.160.151.xxx | 21-05-2008 17:58:02
IT was nice. Keep up te good work!!!
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
 
Security Image
Please input the anti-spam code that you can read in the image.

Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved.

 
Tag it:
Delicious
Furl it!
Spurl
digg
YahooMyWeb
< Prev   Next >
 

Google Search

Google