Batch-如果基于文件/网站的语句打开 [英] Batch- If statements based on files/websites open

查看:137
本文介绍了Batch-如果基于文件/网站的语句打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我上一个问题中,基于打开程序的Batch if语句,我问如何基于打开一个程序来创建批处理if语句。

In my previous question, Batch if statements based on opening a program, I asked how to make a batch if statement based on opening a program.

我可以根据以下条件创建批处理文件 IF

Can I make a batch-file IF statement based off:


  1. 在浏览器中的文件路径:eg C:\USERS\admin\desktop\

  1. File Paths in explorer: e.g. "C:\USERS\admin\desktop\"

档案:例如James.csv

Files: e.g. "James.csv"

网站: http://www.google.com

为了使我的问题更清楚:

To make my question a bit clearer:

@echo off
Set WinProcess1=D:\PFI.vbs
Set WinProcess2=c:\
Set WinProcess3=http://www.google.com

:props
tasklist /FI "IMAGENAME eq %WinProcess1%" | find /C /I "%WinProcess1%" >nul
if not ErrorLevel 1 (taskkill /f /im %WinProccess1% & echo a )
tasklist /FI "IMAGENAME eq %WinProcess1%" I find /C /I "%WinProcess1%" >nul 
if not ErrorLevel 1 (echo b & timeout /T 1 /NOBREAK >NUL)
tasklist /FI "IMAGENAME eq %WinProcess2%" | find /C /I "%WinProcess2%" > nul
if not ErrorLevel 1 (echo destroy app & timeout /T 1 /NOBREAK >nul )
tasklist /FI "IMAGENAME eq %WinProcess3%" | find /C /I "%WinProcess3%" > nul
if not ErrorLevel 1 ( echo c & timeout /T 1 /NOBREAK >nul )
goto props 

这个循环将简单地检查 winprocess1,2或3 是否正在运行, echo a,b或c 如果文件/网站/路径是打开的。如果没有,那么它会再次运行。

This loop would simply check if winprocess1,2, or 3 were running and echo a,b, or c if the file/website/path were open. If not, then it would run again.

编辑:打开,我的意思是一个程序正在使用它。例如,如果您尝试通过浏览器重命名一个文档,当它打开时,它会给你一个程序(例如)微软的单词正在使用它。

by open, I mean a program is using it. For example, if you try to rename a document via explorer while it is open, it will give you a message saying that a program (e.g) Microsoft word is using it.

推荐答案

对于第二种情况,请下载Microsoft的处理实用程序,则可以检查文件是否打开:

For the 2nd case download Microsoft's handle utility, then you can check if the file is opened:


  • 在任何位置:

  • anywhere:

handle "James.csv"


  • in a specific program:

  • in a specific program:

    handle -p excel.exe "James.csv"
    


  • 条件处理示例:

    handle "James.csv" | find "pid:" >nul && (echo Found) || (echo Not found)
    

    这篇关于Batch-如果基于文件/网站的语句打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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