I'm using powershell to
- Close Access Database,
- Download updated Access front end to local machines,
- Update (overwrite) local documents, and
- Launch the Access database with parameters using
cmd.exe
.
Everything works fine, but the Exit
command doesn't work after using cmd.exe
command to launch the database.
If I comment out the cmd.exe
command, then the Exit
command works just fine. But if I use the Exit
command, the script stops there and the Exit
command does not work. 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
CodePudding user response:
cmd.exe
will block until MSACCESS.EXE
exits.
To make cmd.exe
launch the program and return immediately, use the start
command:
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:
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"