I want to make a small VBS script which tells user if file is in use or not. I have one file and if this file is in use VBS should give me a message that file is in use. If file is not in use by any process, VBS should give me message that file not in use. I tried this but nothing works.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could try with a WMI query:
filename = "..."
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_Process WHERE CommandLine LIKE '%" & filename & "%'"
For Each p In wmi.ExecQuery(qry)
WScript.Echo "Media file in use."
WScript.Quit 0
Next
WScript.Echo "Media file not in use."