我使用多个使用不同用户凭据的资源管理器窗口,我想知道是否有一种方法可以为每个窗口设置一个静态标题,以便能够确定哪个窗口使用哪个用户凭据,例如窗口 A 标题设置为“用户 abc " - 因为标题更改为当前打开的目录,有时打开多个窗口会让人感到困惑
我正在寻找尽可能简单的解决方案,批处理、VBScript 等,可以从命令行或脚本文件轻松运行的东西,不需要任何编译、转换或安装特定软件,例如:
open explorer.exe title="custom title"
到目前为止,我找不到任何可以处理这个问题的脚本——第三方应用程序是不可能的。
不确定这是否可能,现在已经尝试了几天但无济于事。
可以使用 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')