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

but5z9lq  于 2023-04-06  发布在  Shell
关注(0)|答案(2)|浏览(235)

我使用多个使用不同用户凭据的资源管理器窗口,我想知道是否有一种方法可以为每个窗口设置一个静态标题,以便能够确定哪个窗口使用哪个用户凭据,例如窗口标题设置为“用户abc”-因为标题更改为当前打开的目录,这在多个窗口打开时有时会引起混淆
我正在寻找尽可能简单的解决方案,批处理,VBScript等,可以很容易地从命令行或脚本文件运行,不需要任何编译,转换或安装特定的软件,例如:

open explorer.exe title="custom title"

到目前为止,我还没有找到任何脚本可以处理-第三方应用程序是不可能的。
不知道这是不是可能的,试着找了几天什么都没有找到。

ulmd4ohb

ulmd4ohb1#

可以使用PowerShell更改文件资源管理器Windows的标题。
要获取所有资源管理器窗口的句柄,请使用此COM对象。
stackoverflow - Powershell script to list all open Explorer windows

(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: Changing Window Titles using 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')
x9ybnkn6

x9ybnkn62#

根据here,它可以为iexplorer(internet explorer)执行此操作,因此通过盲目猜测,可能可以以相同的方式为explorer windows〉run〉regedit.exe HKEY_CURRENT_USER〉Software〉Microsoft〉Windows〉CurrentVersion〉Explorer执行此操作,并使用字符串作为值类型,窗口标题作为值名称
通过改变主题,可以实现相同或相似的目标,here解释的所有内容都可以通过批处理脚本完成。

相关问题