为什么当我运行批处理文件并打开许多应用程序时,cmd.exe 保持打开状态。我该如何修复它(使其保持关闭状态)?

为什么当我运行批处理文件并打开许多应用程序时,cmd.exe 保持打开状态。我该如何修复它(使其保持关闭状态)?

这是我的批次

@echo off
start "Start OneDrive" "C:\Users\username\AppData\Local\Microsoft\OneDrive\OneDrive.exe"
start  "Start Google Sync" "C:\Program Files\Google\Drive\GoogleDriveSync.exe"
start "Start Clipboard" "C:\Program Files\Beyond Compare 4\BCClipboard.exe"
start "Start Cisco AnyConnect" "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
start outlook
start chrome
start firefox
start skype
start "Start Teams" "C:\Users\username\AppData\Local\Microsoft\Teams\current\Teams.exe"
start Slack
start Zoom
sleep 15
taskkill /IM "explorer.exe"
taskkill /IM "teams.exe"
taskkill /IM "skype.exe"
taskkill /IM "slack.exe"
taskkill /IM "zoom.exe"
@echo on

我明白了这个错误当它影响到团队时(这不是我要问的问题):由于团队中未处理的错误,它使 CMD 保持打开状态,光标闪烁。您可以忽略以下错误,它仅用于上下文。 问题在于应用程序错误导致 CMD 保持打开状态。

(electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false".  It will change to be "true" in Electron 9.  For more information please check https://github.com/electron/electron/issues/18397
Error while parsing hooks JSON. Error: "ENOENT: no such file or directory, open 'C:\\Users\\username\\AppData\\Roaming\\Microsoft\\Teams\\hooks.json'"
(node:27472) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ecsSettingsUpdated listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
(electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false".  It will change to be "true" in Electron 9.  For more information please check https://github.com/electron/electron/issues/18397
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.
(node:27472) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 appInitialized listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
(node:27472) UnhandledPromiseRejectionWarning: undefined
(node:27472) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:27472) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error occurred in handler for 'keychain:get-password': Error: No stored credentials fetched from keytar.
    at C:\Program Files\WindowsApps\Microsoft.SkypeApp_15.68.96.0_x86__kzf8qxf38zg5c\Skype\resources\app.asar\main.js:2:600216
    at async electron/js2c/browser_init.js:6048:30
Error occurred in handler for 'keychain:get-password': Error: No stored credentials fetched from keytar.
    at C:\Program Files\WindowsApps\Microsoft.SkypeApp_15.68.96.0_x86__kzf8qxf38zg5c\Skype\resources\app.asar\main.js:2:600216
    at async electron/js2c/browser_init.js:6048:30
(electron) 'systemPreferences.isInvertedColorScheme()' is deprecated and will be removed. Please use 'nativeTheme.shouldUseInvertedColorScheme' instead.
(node:27472) UnhandledPromiseRejectionWarning: Error: [RegistryKey] Unable to open registry key: HKEY_CURRENT_USER\SOFTWARE\IM Providers failed: The operation completed successfully.
    at RegistryService.registerImProviderCu (C:\Users\username\AppData\Local\Microsoft\Teams\current\resources\app.asar\lib\registryService.js:586:72)
    at C:\Users\username\AppData\Local\Microsoft\Teams\current\resources\app.asar\lib\registryService.js:167:41
(node:27472) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:27472) UnhandledPromiseRejectionWarning: Error: [RegistryKey] Unable to open registry key: HKEY_CURRENT_USER\SOFTWARE\IM Providers failed: The operation completed successfully.
    at RegistryService.registerImProviderCu (C:\Users\username\AppData\Local\Microsoft\Teams\current\resources\app.asar\lib\registryService.js:586:72)
    at C:\Users\username\AppData\Local\Microsoft\Teams\current\resources\app.asar\lib\registryService.js:167:41
(node:27472) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
SUCCESS: Sent termination signal to the process "explorer.exe" with PID 14384.
SUCCESS: Sent termination signal to the process "explorer.exe" with PID 25908.
SUCCESS: Sent termination signal to the process "Teams.exe" with PID 27472.
SUCCESS: Sent termination signal to the process "Teams.exe" with PID 25612.
ERROR: The process "Teams.exe" with PID 18836 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "Teams.exe" with PID 27476 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "Teams.exe" with PID 13548 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "Teams.exe" with PID 20888 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "Teams.exe" with PID 24916 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "Teams.exe" with PID 23860.
ERROR: The process "Teams.exe" with PID 5708 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "Skype.exe" with PID 22604.
SUCCESS: Sent termination signal to the process "Skype.exe" with PID 27620.
SUCCESS: Sent termination signal to the process "Skype.exe" with PID 5252.
ERROR: The process "Skype.exe" with PID 9844 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "Skype.exe" with PID 7404.
ERROR: The process "Skype.exe" with PID 8976 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "slack.exe" with PID 17188.
SUCCESS: Sent termination signal to the process "slack.exe" with PID 6704.
SUCCESS: Sent termination signal to the process "slack.exe" with PID 2868.
ERROR: The process "slack.exe" with PID 24196 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "slack.exe" with PID 23300 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
SUCCESS: Sent termination signal to the process "Zoom.exe" with PID 11976.
SUCCESS: Sent termination signal to the process "Zoom.exe" with PID 17976.
_

我所想要的只是应用程序运行并且 CMD 不要保持打开状态。

应用程序运行正常(忽略错误),但 cmd.exe 窗口保持打开状态。

答案1

这对我来说很有效,我没有使用start cmd /c,只是start得到了错误。顺便说一句,我读到 Windows 现在推荐使用 Powershell 来执行此操作,而不是CMD

答案2

更新:

这个答案确实有效。但出于某种原因,它需要为每个应用程序使用开关 /c 启动 cmd。因此会打开多个 cmd.exe 窗口然后关闭。这需要 sleep 10,否则 taskkills 会运行得太快

我发现当我从批处理中运行团队应用程序时,它会顺利处理,但批处理的其余部分会停止。如果我收到错误,其余部分会处理,但 cmd 会保持打开状态。


主要批次变更:

@echo off
start cmd /c start "Start OneDrive" "C:\Users\username\AppData\Local\Microsoft\OneDrive\OneDrive.exe"
start cmd /c start  "Start Google Sync" "C:\Program Files\Google\Drive\GoogleDriveSync.exe"
start cmd /c start "Start Clipboard" "C:\Program Files\Beyond Compare 4\BCClipboard.exe"
start cmd /c start "Start Cisco AnyConnect" "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
start cmd /c start outlook
start cmd /c start chrome
start cmd /c start firefox
start cmd /c start Slack
start cmd /c start Zoom
start cmd /c start skype
start cmd /c start "Start Teams" "C:\Users\username\AppData\Local\Microsoft\Teams\current\Teams.exe"
sleep 10
taskkill /IM "explorer.exe"
taskkill /IM "slack.exe"
taskkill /IM "zoom.exe"
taskkill /IM "skype.exe"
taskkill /IM "teams.exe"
@echo on

我做到了不是结果将 teams.exe 放入其自己的批处理中在单独的环境中运行,它在某种程度上存在缺陷。

我没有用过这个次要批次“StartTeams.bat”

start "Start Teams" "C:\Users\username\AppData\Local\Microsoft\Teams\current\Teams.exe"
exit /b

我确实尝试过其他建议的答案,但不幸的是,它对我不起作用。我的答案已经多次改变,以为我解决了它,结果却带来了新的问题。


但我想我已经找到了答案。我很想得到一些其他的答案,因为这个主题相当复杂。我不知道为什么我必须使用“start cmd /c start...”才能让它工作。

相关内容