Check if VBS file is used

I want to make a small VBS script that tells the user whether the file is used or not. Specifically, I have one file, and if this file is used, VBS will show me a message that the file is being used. If the file is not used by any process, VBS shows me a message that the file is not used. I tried this , but it does not show me any messages.

+5
source share
1 answer

You can try using a WMI request:

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."
+8
source

All Articles