Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 批处理-基于打开的文件/网站的If语句_Windows_Batch File_Cmd - Fatal编程技术网

Windows 批处理-基于打开的文件/网站的If语句

Windows 批处理-基于打开的文件/网站的If语句,windows,batch-file,cmd,Windows,Batch File,Cmd,在我的上一个问题中,我问了如何基于打开一个程序生成一个批处理if语句 我是否可以根据以下内容生成批处理文件IF语句: 资源管理器中的文件路径:例如“C:\USERS\admin\desktop\” 文件:例如“James.csv” 网站:例如“ 让我的问题更清楚一点: @echo off Set WinProcess1=D:\PFI.vbs Set WinProcess2=c:\ Set WinProcess3=http://www.google.com :props tasklist /FI

在我的上一个问题中,我问了如何基于打开一个程序生成一个批处理if语句

我是否可以根据以下内容生成批处理文件
IF
语句:

  • 资源管理器中的文件路径:例如“C:\USERS\admin\desktop\”

  • 文件:例如“James.csv”

  • 网站:例如“

  • 让我的问题更清楚一点:

    @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
    文件/网站/路径是否打开。如果没有,那么它将再次运行


    编辑:我所说的“打开”,是指程序正在使用它。例如,如果您试图在文档打开时通过资源管理器重命名文档,它会给您一条消息,告诉您有一个程序(例如)Microsoft word正在使用它。

    对于第二种情况,请下载Microsoft的实用程序,然后您可以检查该文件是否已打开:

    • 任何地方:

      handle "James.csv"
      
    • 在特定程序中:

      handle -p excel.exe "James.csv"
      
    条件处理的示例:

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

    程序如何使用网站?举一些你的任务的例子。FWIW文件在使用时可以重命名-只有在程序将其锁定/打开以供独占使用时才会失败。您可以改用
    WINDOWTITLE
    。一些应用程序显示窗口标题中打开的内容。但它不是100%可靠的。您可以使用的一个轨道是列出可以打开vbs的程序;http,然后检查findstr是否与文件或网站的标题名匹配。您能否显示代码的外观?