设置 Windows 资源管理器窗口标题

问题描述 投票:0回答:2

我使用多个使用不同用户凭据的资源管理器窗口,我想知道是否有一种方法可以为每个窗口设置一个静态标题,以便能够确定哪个窗口使用哪个用户凭据,例如窗口 A 标题设置为“用户 abc " - 因为标题更改为当前打开的目录,有时打开多个窗口会让人感到困惑

我正在寻找尽可能简单的解决方案,批处理、VBScript 等,可以从命令行或脚本文件轻松运行的东西,不需要任何编译、转换或安装特定软件,例如:

open explorer.exe title="custom title"

到目前为止,我找不到任何可以处理这个问题的脚本——第三方应用程序是不可能的。

不确定这是否可能,现在已经尝试了几天但无济于事。

vba batch-file vbscript windows-7 explorer
2个回答
0
投票

可以使用 PowerShell 更改文件资源管理器窗口的标题。

要获取所有资源管理器窗口的句柄,请使用此 COM 对象。
stackoverflow - 用于列出所有打开的资源管理器窗口的 Powershell 脚本

(New-Object -ComObject 'Shell.Application').Windows() | select Name,LocationName,HWND

要获取最顶层文件资源管理器窗口的句柄,您可以使用
stackoverflow - 将文件资源管理器当前工作目录传递给 PowerShell 脚本

Add-Type -Namespace Util -Name WinApi  -MemberDefinition @'
  // Find a window by class name and optionally also title.
  // The TOPMOST matching window (in terms of Z-order) is returned.
  // IMPORTANT: To not search for a title, 
  // pass [NullString]::Value, not $null, to lpWindowName
  [DllImport("user32.dll")]
  public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
'@

$hwndTopMostFileExplorer = [Util.WinApi]::FindWindow(
  "CabinetWClass",     # the window class of interest
  [NullString]::Value  # no window title to search for
)

(New-Object -ComObject Shell.Application).Windows() |
  Where-Object hwnd -eq $hwndTopMostFileExplorer

要更改所选文件资源管理器的标题,请使用适当的句柄。
下面示例中使用的句柄用于最顶层的资源管理器窗口。
Pete Hinchley:使用 PowerShell 更改窗口标题

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;

public static class Win32 {
  [DllImport("User32.dll", EntryPoint="SetWindowText")]
  public static extern int SetWindowText(IntPtr hWnd, string strTitle);
}
"@

[Win32]::SetWindowText($hwndTopMostFileExplorer , 'My Custom Title')


-2
投票

根据here可以为iexplorer(Internet Explorer)做这件事 所以通过盲目猜测,可能会以同样的方式为资源管理器做这件事 Windows>运行>regedit.exe HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Explorer 和一个以字符串为值类型、窗口标题为值名称的新数据

通过改变主题,可以实现相同或相似的目标,所有解释here都可以用批处理脚本完成

© www.soinside.com 2019 - 2024. All rights reserved.