&引用;“带到前面去”;对于Windows XP命令shell
是否可以将命令放入Windows XP.bat文件中,以将命令shell置于前端?来自批处理文件,否。如果要激活窗口,必须使用。如果你不想弄脏windows编程,但仍然想激活windows和类似的简单东西,我强烈建议你离开。您可以随时从批处理文件调用此程序,让它执行任务。将执行此操作,尽管它需要一些脚本&引用;“带到前面去”;对于Windows XP命令shell,windows,batch-file,windows-shell,Windows,Batch File,Windows Shell,是否可以将命令放入Windows XP.bat文件中,以将命令shell置于前端?来自批处理文件,否。如果要激活窗口,必须使用。如果你不想弄脏windows编程,但仍然想激活windows和类似的简单东西,我强烈建议你离开。您可以随时从批处理文件调用此程序,让它执行任务。将执行此操作,尽管它需要一些脚本 nircmd win activate "titleofwindow" 您基本上需要知道正在执行的cmd窗口的标题(您可以通过windows中的title命令进行设置) 因此: 我们应该做到这
nircmd win activate "titleofwindow"
您基本上需要知道正在执行的cmd窗口的标题(您可以通过windows中的title命令进行设置)
因此:
我们应该做到这一点
注意:一些恶意软件工具利用NirCmd可执行文件(它不需要部署,因为它非常强大),这可能会给您带来问题。对于这一点以及其他需要添加一些功能的DOS编程任务也很有用。简单易用,有很好的文档记录。请注意您的防病毒程序,尽管-CMDOW可以隐藏您的防病毒程序可能会发现的病毒窗口。只需将其添加到例外列表中即可。CMDOW是完全可移植的,绝对不是病毒,如果您担心它被第三方用来隐藏某些内容,只需将其塞进某个不明显的文件夹中即可。另一种按名称切换到窗口的快速方法是通过Ctrl+Shift+Esc,它会打开任务管理器。然后只需键入windows标题的前几个字母来选择进程,然后按Enter键。另一种让cmd提示符窗口显示在前面的方法是,在file1.bat末尾添加一个调用第二个file2.bat文件的命令,然后是一个exit命令 示例使用 file1.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”|查找“program.exe”
如果错误级别1(program.exe)为其他(BringToFront.exe“程序窗口标题”)请尝试
出于某种原因,我需要指定标题:nircmd win activate title“title”这是一个非常棒的技巧!只有一个问题。。。它将使用最近打开的选项卡打开。如果是“应用程序”选项卡,很好,但如果是另一个选项卡,则需要一组更精细的击键。。。如果执行
Ctrl+Shift+Esc
,将启动任务管理器<代码>Shift+Tab将选择选项卡栏。点击左箭头几次,最终会选择“应用程序”选项卡(因为它不会循环,这是最左边的,所以你很好。)tab
要返回列表,请键入窗口名称,然后点击Enter
。如果有人认为我疯狂地认为这很有用,自动击键非常简单,并且很少有外部库依赖项。单单Python就足以实现按键的自动化。另一方面,读取windows坐标和自动化鼠标是非常棘手的。因此,只需键盘输入即可工作的自动化解决方案非常棒。此外,多次按左箭头可以替换为一次按到家。
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");
}
}
}
call focusOn.bat "My Title"