Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Check if a database is open, if so, close it

    I have a batch file that decompiles my backend database every night. Once in a while someone will forget to close their fronted before leaving work and it causes problems. Is there a way to have a batch file check if a database is open and if it is open, close it?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Schultz,

    I'll make a couple of assumptions here since you didn't specify.

    1. We're talking about MS Access.
    2. The individuals are leaving their machines running.

    Some possibilities to investigate:

    A scheduled task on each users machine that would run after normal business hours (could be hard to define) that would run a PowerShell program to check for the Access process and using the Stop-Process cmdlet to shut it down.

    Using PowerShell remoting (would initially have to be setup on each machine) to allow you to check and shutdown via PowerShell program or using the PS ISE.

    If I may ask why are you decompiling your Back end? I could understand compacting but usually all the code (which what benefits from decompiling) is in the Front end so you could move the code out of the BE and eliminate the need to decompile. I used to use a batch file to fetch the latest copy of the FE from the Server on boot of the client insuring the users had the latest version. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes, we're running Microsoft Access 2010, AND all machines are left running all the time. I'm glad you asked the question about the backend. I did not present my problem correctly, it was misleading. I am actually decompiling my frontend, and compacting my backend. The frontend that I decompile is obviously an .accdb which I call GTDevelop. The backend is GTData.mdb. A friend recommended I keep the data in .mdb format so I just took his advice, but the frontend is .accdb. Everytime I push out an update, I publish it as an .accde and rename it DataEntery.accde. Every night a batch file also runs pushing out the .accde to each client so they have the latest version.

    I have rarely used PowerShell, but that shouldn't be a problem to set up on each client. I'll do some research on what you suggested. Thanks!

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Shultz,

    Here's some PowerShell you can use:
    Code:
    $ErrorActionPreference = 'SilentlyContinue'
    $ Test = Get-Process -Name "MSACCESS" 
    if ($Test -ne $null) {
     Stop-Process -Force -Name "MSACCESS"
    }
    Just save the code to a file like Stop-Access.ps1.

    Then setup a scheduled task to fire it up after business hours.

    If you haven't used PS before you need to setup it up. See Post #2 here.

    To setup the Scheduled Task:
    In the Action Tab -> New
    Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe
    Add Arguments: [d]:\[your path here]\Stop-Access.ps1

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OK. Thanks. I've been busy on a tech call most the afternoon, will try this tomorrow.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •