Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Bby67
Femeie
19 ani
Bucuresti
cauta Barbat
19 - 70 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [VBS] Delete Folders and Contents Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
I periodically have a problem with one of the programs I use - a part of it stops working for some reason.
This happens once or twice a month.

The support people directed me to delete 2 of the program's temp folders in order to fix my issue.

And it works fine.

But each time I have to browse a location and delete those temp folders.

Not that it takes time, but it's nicer when you can do it with a couple of clicks.

The following VBS does just that. It can, of course, be simplified a lot, but I want it this way:


Dim filesys
Dim i
Dim j

' ##### this part closes PROGRAM.exe in case it's open, otherwise you won't be able to delete the temp folders
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'PROGRAM.exe'")
For Each objProcess in colProcess
  On Error Resume Next
  objProcess.Terminate()
Next
' #####

WScript.Sleep 1000 ' the script needs to sleep for a second to give the PROGRAM time to properly exit

' ##### this part may be simplified a lot, to something as simple as:
' filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\
FOLDER1"
' filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\FOLDER2"

Set filesys = CreateObject("Scripting.FileSystemObject")

i = 0
j = 0

If filesys.FolderExists("C:\Users\Mrrrr\AppData\Local\Temp\FOLDER1\") Then
   i = i + 1
End If

If filesys.FolderExists("C:\Users\Mrrrr\AppData\Local\Temp\FOLDER2\") Then
   j = j + 1
End If

If i = 1 And j = 1 Then
   filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\FOLDER1"
   filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\FOLDER2"
   Msgbox("FOLDER1 & FOLDER2 folders were deleted")
Else

If i = 1 And j = 0 Then
   filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\FOLDER1"
   Msgbox("FOLDER1 folder deleted, FOLDER2 folder doesn't exist")
Else

If i = 0 And j = 1 Then
   filesys.DeleteFolder "C:\Users\Mrrrr\AppData\Local\Temp\FOLDER2"
   Msgbox("FOLDER2 folder deleted, FOLDER1 folder doesn't exist")
Else
   Msgbox("Nothing deleted - FOLDER1 & FOLDER2 folders don't exist")

End If
End If
End If


_______________________________________


pus acum 3 ani
   
Pagini: 1  

Mergi la