gpt4 book ai didi

windows - bat 文件运行后关闭 Windows 应用程序

转载 作者:可可西里 更新时间:2023-11-01 11:53:48 26 4
gpt4 key购买 nike

在我的批处理文件中,我打开了一个文件并打印了它的内容。现在我正在尝试关闭应用程序。我从 cmd 行使用了 taskkill/f/im Ptedit50.exe,程序关闭。我无法让它在批处理文件中工作。当我在打印命令之后添加该行时,它们程序退出并且打印命令永远不会执行。如果我在批处理文件的末尾插入该行,程序不会退出。我应该在哪里放置 taskkill/f/im Ptedit50.exe 行?

@echo off
setlocal

title My First batch file
echo Hello!
start Ptedit50.exe "c:\My Labels\PraxisBadge.lbx"

call :SendCtrlP "Name in Windowtitle"

exit /b

:SendCtrlP <app>
setlocal
set vbs=%Temp%\_.vbs
>%vbs% echo set s = CreateObject("Wscript.Shell")
>>%vbs% echo s.appactivate "%~1"
>>%vbs% echo s.sendkeys "^p"
>>%vbs% echo s.sendkeys "{ENTER}"
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
exit /b

taskkill /f /im Ptedit50.exe
exit /b
enter code here

最佳答案

这是一个批处理 + JScript 混合示例。我添加了几个 2 秒的休眠时间,让目标程序有时间处理请求。通常,应用程序会启动一个单独的打印对话框,因此我将其更改为将回车键发送到打印对话框。

@if (@CodeSection == @Batch) @then

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The first line in the script is...
:: in Batch, a valid IF command that does nothing.
:: in JScript, a conditional compilation IF statement that is false.
:: So the following section is omitted until the next "[at]end".
:: Note: the "[at]then" is required for Batch to prevent a syntax error.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Batch Section

@echo off
:: Open Labels
start Ptedit50.exe "c:\My Labels\PraxisBadge.lbx"
:: Wait 2 Seconds
ping 192.0.2.2 -n 1 -w 2000 >nul
:: Send Ctrl+P and Enter
CScript //E:JScript //Nologo "%~f0" "Name in Windowtitle" "^p"
CScript //E:JScript //Nologo "%~f0" "Print" "~"
:: Wait 2 Seconds
ping 192.0.2.2 -n 1 -w 2000 >nul
:: Kill Program
taskkill /f /im Ptedit50.exe
exit /b 0

:: End of Batch
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@end
////////////////////////////////////////////////////////////////////////////////
// JScript Section

try
{
var WshShell = WScript.CreateObject('WScript.Shell');
var Title = WScript.Arguments.Item(0);
var Message = WScript.Arguments.Item(1);
WshShell.AppActivate(Title);
WshShell.SendKeys(Message);
WScript.Quit(0);
}
catch(e)
{
WScript.Echo(e);
WScript.Quit(1);
}
WScript.Quit(2);

关于windows - bat 文件运行后关闭 Windows 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22488561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com