为Windows XP命令行提供“前置”function

有没有一个命令,我可以把一个Windows XP的.bat文件,把命令shell的前面?

从批处理文件中,不。 如果你想激活一个窗口,你必须使用SetActiveWindow() 。 如果你不想弄脏Windows编程,但仍然想要激活Windows和简单的东西,我强烈建议检查出自动 。 你总是可以从你的批处理文件中调用这个程序来完成这个任务。

nircmd会这样做,尽管它涉及一些脚本。

nircmd win activate "titleofwindow" 

您基本上需要知道正在执行的cmd窗口的标题(您可以通过Windows中的TITLE命令来设置它)

从而:

 TITLE %SOME_UNIQUE_VALE% nircmd win activate %SOME_UNIQUE_VALE% 

应该做的伎俩。

请注意,一些恶意软件工具使用NirCmd可执行文件(它不需要部署,功能非常强大),这可能会导致您的问题。

另一种让cmd提示窗口显示在前面的方法是用一个命令结束file1.bat来调用第二个file2.bat文件,然后是一个退出命令。

使用file1.bat的示例

 .... [your code here] start C:\file2.bat exit 

这将关闭file1.bat并打开第二个.bat文件,您可以在其中继续执行代码。 第二个.bat命令提示符将在其他窗口前面打开

CMDOW对于这个以及其他DOS编程任务也是有用的,在这些任务中需要一些附加功能。 易于使用和有据可查。 但是,请注意您的防病毒程序 – CMDOW有能力隐藏您的防病毒程序将会作为可能的病毒获取的窗口。 只需将其添加到您的例外列表。 CMDOW是完全可移植的,绝对不是病毒,如果你有任何担心被第三方用来隐藏某些东西,只需把它放在某个非显而易见的文件夹中。

我有一个类似的问题,我不得不开发一个简单的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”| 找到“program.exe”如果错误级别1(program.exe)其他(BringToFront.exe“程序窗口标题”)

另一种通过名称切换到窗口的快捷方法是通过Ctrl + Shift + Esc打开任务管理器。 然后,只需键入窗口标题的前几个字母来选择进程,然后按Enter键。