Windows XP命令shell的"带到前面"

Lau*_*els 6 windows batch-file windows-shell

是否有一个命令可以放入Windows XP .bat文件中以将命令shell放到前面?

Shu*_*oUk 10

nircmd会这样做,虽然它涉及一些脚本.

nircmd win activate "titleofwindow"
Run Code Online (Sandbox Code Playgroud)

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

从而:

TITLE %SOME_UNIQUE_VALE%
nircmd win activate %SOME_UNIQUE_VALE%
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩.

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


小智 6

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

使用 file1.bat 的示例

....
[your code here]
start C:\file2.bat
exit
Run Code Online (Sandbox Code Playgroud)

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


Pan*_*ciz 5

我遇到了类似的问题,我必须开发一个简单的 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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的批处理脚本的代码类似于:

tasklist  /FI "IMAGENAME eq program.exe" | find "program.exe"
if errorlevel 1 (program.exe) else (BringToFront.exe "Program Window Title")
Run Code Online (Sandbox Code Playgroud)


rye*_*guy 4

从批处理文件来看,没有。如果你想激活一个窗口,你必须使用SetActiveWindow()。如果您不想搞 Windows 编程,但仍想激活 Windows 和类似的简单东西,我强烈建议您查看AutoIt。您始终可以从批处理文件中调用该程序以让它完成任务。