#1 03 Sep 2010 09:28

scott_humphris
Member
Registered: 03 Sep 2010
Posts: 7

VBScript - Delete multiple files

can anyone help me with a script that will delete two files at once from specified paths?

Offline

#2 03 Sep 2010 10:10

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 873
Website

Re: VBScript - Delete multiple files

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile ("C:\docs\test1.txt")
objFSO.DeleteFile ("C:\docs\test2.txt")

see here for more options
http://ss64.com/vb/filesystemobject.html

and heres a complete script for cleaning out files from a Roaming Profile:
http://ss64.com/vb/syntax-profile.html

Offline

#3 03 Sep 2010 11:11

scott_humphris
Member
Registered: 03 Sep 2010
Posts: 7

Re: VBScript - Delete multiple files

Thanks very much simon.

Also i am using this script to kill a process:

Const strComputer = "." 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'outlook.exe'")
  For Each objProcess in colProcessList 
    objProcess.Terminate()

How can i get it to kill more than one process.
Thanks for your help.

Offline

#4 03 Sep 2010 11:27

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 873
Website

Re: VBScript - Delete multiple files

Just change the Select statement:

SELECT * FROM Win32_Process WHERE Name = 'outlook.exe' or Name = 'Somethingelse.exe'

Offline

#5 09 Jan 2011 17:06

arash
Member
Registered: 27 Apr 2010
Posts: 27

Re: VBScript - Delete multiple files

Dear Simon is there a better way to terminate several processes?
I mean in case of many processes to kill, it is a bit disorientating to add all processes name in the middle of the code.
I am wondering if it is possible to enter all processes name at the top of the code as parameters and then the vbscript do the rest.
thanks

Offline

#6 05 Nov 2014 02:41

bars143
New Member
Registered: 05 Nov 2014
Posts: 2

Re: VBScript - Delete multiple files

scott_humphris wrote:

Thanks very much simon.

Also i am using this script to kill a process:

Const strComputer = "." 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'outlook.exe'")
  For Each objProcess in colProcessList 
    objProcess.Terminate()

How can i get it to kill more than one process.
Thanks for your help.

hi im newbie here,

its my first post and just ask of above script of what code to be added that popup message that outlook.exe is stopped.

i know a batch script equivalent is "echo".

thanks,

Bars

Offline

#7 05 Nov 2014 09:56

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 873
Website

Re: VBScript - Delete multiple files

Offline

#8 05 Nov 2014 15:25

bars143
New Member
Registered: 05 Nov 2014
Posts: 2

Re: VBScript - Delete multiple files

option explicit
Const strComputer = "."
Dim objWMIService, colProcessList, objProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'cmd.exe'")
    If colProcessList.Count > 0 Then
    On Error Resume next
        For Each objProcess in colProcessList
            objProcess.Terminate()
        WScript.Echo "Process terminated: cmd.exe"           
        Next
        On Error goTo 0
    Else
        WScript.Echo "Process not found: cmd.exe"
    End If

thank i made it work. i had it done many hours trying to use "WScript.Echo" with batch-like "if-else" command. but its error messages are too many and afterward it always help faster due to its description of error which i google it error code all the time.

hi ! Simon Sheppard,

can you help me find a website link that provide a complete list of error code?

Offline

Board footer

Powered by FluxBB