简体   繁体   English

Powershell 运行 Cmd.exe 后不会退出

[英]Powershell Won't Exit After Running Cmd.exe

I'm using powershell to我正在使用 powershell 来

  1. Close Access Database,关闭访问数据库,
  2. Download updated Access front end to local machines,将更新的 Access 前端下载到本地机器,
  3. Update (overwrite) local documents, and更新(覆盖)本地文档,以及
  4. Launch the Access database with parameters using cmd.exe .使用cmd.exe启动带有参数的 Access 数据库。

Everything works fine, but the Exit command doesn't work after using cmd.exe command to launch the database.一切正常,但使用cmd.exe命令启动数据库后Exit命令不起作用。

If I comment out the cmd.exe command, then the Exit command works just fine.如果我注释掉cmd.exe命令,那么Exit命令就可以正常工作。 But if I use the Exit command, the script stops there and the Exit command does not work.但是,如果我使用Exit命令,脚本会停在那里并且Exit命令不起作用。 Below is the entire code that I'm talking about.下面是我正在谈论的整个代码。

## Close Microsoft Access
Stop-process -name MSACCESS -Force

## Download updated Access database to local machine
Copy-Item "F:\New_DB\Win7DBDocs\WC_Sys.mdb" -Destination "C:\DB_Docs" -Recurse -Force

## Copy Documents and Spreadsheets to local machine
echo "Overwriting files C:\DB_WPDocs"
Copy-Item -Path "F:\New_DB\DB_WPDocs\*" -Destination "C:\DB_WPDocs" -Recurse -Force

## Launch Microsoft Access with Parameters
cmd.exe /c "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\DB_Docs\WC_Sys.mdb" /WRKGRP "F:\DB_Docs\Secured.mdw"

Exit

cmd.exe will block until MSACCESS.EXE exits. cmd.exe将阻塞,直到MSACCESS.EXE退出。

To make cmd.exe launch the program and return immediately, use the start command:要使cmd.exe启动程序并立即返回,请使用start命令:

cmd.exe /c start "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\DB_Docs\WC_Sys.mdb" /WRKGRP "F:\DB_Docs\Secured.mdw"

... or drop cmd.exe completely and use the Start-Process cmdlet instead: ...或完全删除cmd.exe并改用Start-Process cmdlet:

Start-Process "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" -ArgumentList "C:\DB_Docs\WC_Sys.mdb", /WRKGRP, "F:\DB_Docs\Secured.mdw"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM