当vb.net应用程序关闭时运行vbscript? [英] Run a vbscript when vb.net application has closed?

查看:61
本文介绍了当vb.net应用程序关闭时运行vbscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹C:\ Lumia Browser \ Themes。当我的主应用程序关闭时,此文件夹将被删除我的主应用程序运行时无法删除该文件夹,因为我的主应用程序正在使用它。所以我制作了VBScript删除文件夹以避免文件无法被删除,因为它正被另一个进程使用错误。



脚本代码(脚本名为 ClearThemes_LBQG67BKkjhb7i.vbs ):

  set  objFSO = CreateObject(  Scripting.FileSystemObject 
objFSO.DeleteFolder( C:\ Lumia Browser \ Themes
WScript.Quit





我在主应用程序的Form_Closed事件中运行此脚本。唯一的问题是我的主应用程序进程仍在运行,这会导致异常(由另一个进程blablabla使用与上面相同)。



启动脚本的代码:

 如果 ClearThemesOnExit =  True  然后 
Process.Start( C:\ Lumia Browser \ClearThemes_LBQG67BKkjhb7i.vbs
结束 如果





当布尔值ClearThemesOnExit等于True时运行脚本。



我是什么可以做的是不是运行脚本立即删除文件夹,我运行一个脚本,等待,直到我的主应用程序已完全停止然后运行脚本删除文件夹(我也可以合并2个脚本而不是2但是我可以很容易地做到。)


我的主应用程序名称.EXE是Lumia Browser.exe。



我非常虽然它与VB.NET非常相似,但对VBScript缺乏经验。有谁知道如何做到这一点?



(总结:运行一个等待我的主应用程序的脚本,Lumia Browser.exe,已完全停止然后运行脚本,ClearThemes_LBQG67BKkjhb7i .vbs,删除文件夹C:\ Lumia Browser \ Themes

解决方案

别担心我把它弄清楚了myslef 。我只是推迟了脚本,让我的主应用程序有足够的时间关闭。



代码:

  set  objFSO = CreateObject(  Scripting.FileSystemObject
WScript.Sleep 5000 ' < <将程序延迟5秒
objFSO.DeleteFolder( C:\ Lumia Browser \\ \\主题
WScript.Quit





希望这将有助于其他人!


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") :

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:

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")

解决方案

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

Code:

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!


这篇关于当vb.net应用程序关闭时运行vbscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆