批量获取Explorer的孩子 [英] Get Explorer's children in batch

查看:74
本文介绍了批量获取Explorer的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了文件夹快捷方式,我希望它们每次都停止启动新的资源管理器

I created folder shortcuts for my taskbar and I would like them to stop launching a new explorer every time

所以我决定创建一个批处理脚本,但是我无法从explorer.exe中获取孩子

So I decided to create a batch script, howover I can not get the kids from explorer.exe

@echo off
pushd
tasklist /nh /fi "imagename eq explorer.exe C:\Users\danil\Desktop\ISO" | find /i "explorer.exe C:\Users\danil\Desktop\ISO" > nul ||(start explorer.exe C:\Users\danil\Desktop\ISO)

推荐答案

您无法通过检查命令行选项来检查打开的文件夹,因为即使更改为其他参数,参数在整个过程中仍保持不变该窗口中的文件夹.您需要使用可编写脚本外壳对象以获取地址.

You cannot check the opening folders by checking the command line options, because the arguments stay the same across the whole life of the process even after you changed to some other folders in that window. You need to use scriptable shell objects to get the addresses.

如果尚未在资源管理器中打开文件夹,这是一个PowerShell脚本,用于打开该文件夹

Here's a PowerShell script to open a folder if it's not already opened in explorer

$folder = 'C:\Users\danil\Desktop\ISO'
$folderOpened = $false
foreach ($w in (New-Object -ComObject Shell.Application).Windows()) {
    if ($w.LocationURL -ieq ([uri]$folder).AbsoluteUri) { $folderOpened = $true; break }
}
if (-not $folderOpened) { Invoke-Item $folder } # or start $folder

下面是一个等效的混合批处理jscript代码段

Below is an equivalent hybrid batch-jscript snippet

@if (@CodeSection == @Batch) @then

@echo off
cscript //e:jscript //nologo "%~f0" %*
exit /b

@end

// JScript Section

var objShell = new ActiveXObject("shell.application");
var objShellWindows;
objShellWindows = objShell.Windows();

if (objShellWindows != null)
{
    var folder = "file:///C:/Users/danil/Desktop/ISO"; // the folder you want to open
    var folderOpened = 0;
    for (var objEnum = new Enumerator(objShellWindows); !objEnum.atEnd(); objEnum.moveNext())
    {
        if (folder == objEnum.item().LocationUrl)
        {
            folderOpened = 1;
            break;
        }
    }
    if (!folderOpened) // open the folder if it's not already opened
        objShell.Explore(folder); // or objshell.Open(folder)
}

每个资源管理器窗口均由一个InternetExplorer对象表示,该对象可以从 Shell.Windows() 集合.您需要使用文件URI方案,而不是正常的Windows路径,但是它可以工作.当然,如果打开它,您甚至可以进一步更改它以切换到文件夹窗口

Each explorer window is represented by an InternetExplorer object that can be retrieved from the Shell.Windows() collection. You need to use a file URI scheme instead of a normal Windows path, but it works. Of course you can even further change it to switch to the folder window if it's being opened

这篇关于批量获取Explorer的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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