如何使用 .bat 文件重新启动进程
How to restart a process using a .bat file
每次我不小心拔下罗技键盘时,"LCore.exe" 进程都没有响应。我必须手动结束进程并重新启动它。
我想创建一个 .bat 文件来为我执行此操作,但我不知道如何做。
我试过使用这个,但它似乎不起作用。
taskkill /im LCore.exe
start "C:\Program Files\Logitech Gaming Software\LCore.exe"
尝试将/f 添加到taskkill,这将强制终止进程。
解决另一个问题的技巧:
start "" "C:\Program Files\Logitech Gaming Software\LCore.exe"
您的第一个命令要求程序关闭。如果它被挂起,它就无法反应。
请参阅 taskkill /?
并查看力参数的 /f
。
对于非控制台程序,WM_Close
消息会发布到主 window(即,就像您单击标题栏上的红色 X 按钮一样)。使用 /f
时使用 TerminateProcess
(在任务管理器的进程选项卡上停止进程)。
来自帮助
An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.
By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.
和
Remarks
The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.
A process cannot prevent itself from being terminated.
每次我不小心拔下罗技键盘时,"LCore.exe" 进程都没有响应。我必须手动结束进程并重新启动它。
我想创建一个 .bat 文件来为我执行此操作,但我不知道如何做。
我试过使用这个,但它似乎不起作用。
taskkill /im LCore.exe
start "C:\Program Files\Logitech Gaming Software\LCore.exe"
尝试将/f 添加到taskkill,这将强制终止进程。
解决另一个问题的技巧:
start "" "C:\Program Files\Logitech Gaming Software\LCore.exe"
您的第一个命令要求程序关闭。如果它被挂起,它就无法反应。
请参阅 taskkill /?
并查看力参数的 /f
。
对于非控制台程序,WM_Close
消息会发布到主 window(即,就像您单击标题栏上的红色 X 按钮一样)。使用 /f
时使用 TerminateProcess
(在任务管理器的进程选项卡上停止进程)。
来自帮助
An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.
By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.
和
Remarks
The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.
A process cannot prevent itself from being terminated.