Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a folder "C:\Lumia Browser\Themes". This folder gets removed when my main application closes. I can't delete the folder while my main application is running because it's being used by my main application. So I made VBScript which deletes the folder to avoid the "File cannot be deleted because it is being used by another process" error.

Script Code (the script is called "ClearThemes_LBQG67BKkjhb7i.vbs") :
VB
set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\Lumia Browser\Themes")
WScript.Quit


I run this script in the Form_Closed event of my main application. Only problem is that my main application process is still running, this causes an exception (used by another process blablabla same as above).

Code to start the Script:
VB
If ClearThemesOnExit = True Then
   Process.Start("C:\Lumia Browser\ClearThemes_LBQG67BKkjhb7i.vbs")
End If


It runs the script when the boolean ClearThemesOnExit is equal to True.

What I could do is instead of running the Script to delete the folder straight away, I run a script which waits until my main application has completely stopped THEN run the script to delete the folder (I could also merge the 2 scripts together instead of having 2 but that I can do easily).

The name of my main application .EXE is "Lumia Browser.exe".

I am very inexperienced with VBScript although it is very similar to VB.NET. Does anyone know how to do this?

(In summary: Run a script which waits until my main application, "Lumia Browser.exe", has completely stopped THEN run the script, "ClearThemes_LBQG67BKkjhb7i.vbs", to delete the folder "C:\Lumia Browser\Themes")
Posted

1 solution

Don't worry I figured it out myslef. I just delayed the script giving my main application enough time to close.

Code:
VB
set objFSO = CreateObject("Scripting.FileSystemObject")
WScript.Sleep 5000 '<< Delays the program for 5 seconds
objFSO.DeleteFolder("C:\Lumia Browser\Themes")
WScript.Quit


Hope this will help someone else in the future!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900