检查文件是否正在与VBS一起使用 [英] Check if file is in use with VBS

查看:59
本文介绍了检查文件是否正在与VBS一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个小的VBS脚本,告诉用户文件是否正在使用中.我有一个文件,如果此文件正在使用中,VBS应该给我一个消息,表明该文件正在使用中.如果文件没有被任何进程使用,则VBS应该向我发送消息,指出该文件未被使用. 我尝试了,但是没有任何效果.

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.

推荐答案

您可以尝试使用WMI查询:

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

这篇关于检查文件是否正在与VBS一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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