[英]Check if file is in use with VBS
I want to make a small VBS script which tells user if file is in use or not. 我想制作一个小的VBS脚本,告诉用户文件是否正在使用中。 I have one file and if this file is in use VBS should give me a message that file is in use.
我有一个文件,如果这个文件正在使用VBS应该给我一个消息,该文件正在使用中。 If file is not in use by any process, VBS should give me message that file not in use.
如果任何进程未使用该文件,VBS应该向我发出该文件未被使用的消息。 I tried this but nothing works.
我试过这个,但没有任何作用。
You could try with a WMI query: 您可以尝试使用WMI查询:
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."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.