是否有一个命令可以放入 Windows XP .bat 文件中以将命令 shell 置于最前面?
nircmd 可以做到这一点,尽管它涉及一些脚本。
nircmd win activate "titleofwindow"
你基本上需要知道你正在执行的cmd窗口的标题(你可以通过windows中的TITLE命令来设置)
因此:
TITLE %SOME_UNIQUE_VALE%
nircmd win activate %SOME_UNIQUE_VALE%
应该可以解决问题。
注意一些恶意软件工具使用 NirCmd 可执行文件(它不需要部署并且非常强大);这可能会给您带来问题。
让 cmd 提示窗口显示在前面的另一种方法是使用调用第二个 file2.bat 文件的命令结束 file1.bat,然后使用 exit 命令。
使用示例 文件1.bat
....
[your code here]
start C:\file2.bat
exit
这将关闭 file1.bat 并打开第二个 .bat 文件,您可以在其中继续编写代码。第二个 .bat 命令提示符将在其他窗口前面打开
我遇到了类似的问题,我必须开发一个简单的 C# 控制台应用程序,将窗口带到前面。使用窗口标题作为参数来选择窗口。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
const int SW_RESTORE = 9;
public static void bringToFront(string title)
{
// Get a handle to the Calculator application.
IntPtr handle = FindWindow(null, title);
// Verify that Calculator is a running process.
if (handle == IntPtr.Zero)
{
return;
}
if (IsIconic(handle))
{
ShowWindow(handle, SW_RESTORE);
}
Console.WriteLine("Founded ");
SetForegroundWindow(handle);
}
static void Main(string[] args)
{
if (args.Length > 0)
bringToFront(args[0]);
else
Console.WriteLine("specify program window title");
}
}
}
我的批处理脚本的代码类似于
任务列表/FI“IMAGENAME eq program.exe”|找到“程序.exe” if errorlevel 1 (program.exe) else (BringToFront.exe“程序窗口标题”)
从批处理文件来看,没有。如果你想激活一个窗口,你必须使用SetActiveWindow()。如果您不想搞 Windows 编程,但仍想激活 Windows 和类似的简单东西,我强烈建议您查看 AutoIt。您始终可以从批处理文件中调用该程序来让它执行任务。
CMDOW 对于此任务以及需要一些附加功能的其他 DOS 编程任务也很有用。使用简单且有据可查。不过,请注意您的防病毒程序 - CMDOW 能够隐藏您的防病毒程序将其识别为可能的病毒的窗口。只需将其添加到您的例外列表中即可。 CMDOW 是完全可移植的,绝对不是病毒,如果您担心第三方使用它来隐藏某些内容,只需将其隐藏在某个不明显的文件夹中即可。
尝试使用 focusOn.bat
call focusOn.bat "My Title"
按名称切换到窗口的另一种快速方法是通过 Ctrl+Shift+Esc,这会打开任务管理器。然后只需输入窗口标题的前几个字母即可选择该进程,然后按 Enter 键。