Batch file assistance needed


ordnance1

New member
Local time
9:24 AM
Posts
13
OS
Windows 11
I have a MS Access database which uses SQL Server as a backend. I want multiple people to use the database so for ease of distribution I created batch files the go out to a folder and copy the file to a temp folder. That way they always have the latest version if I make changes to the front end. The master file lives in a shared OneDrive folder. The issue I have is that of my users 1 has his OneDrive on his D drive while others have it on their C drive.

Below is my feeble attempt but it does not seem to work. I get no error messages.

Is this even possible?



Untitled picture.png
 

My Computer

System One

  • OS
    Windows 11
I created batch files the go out to a folder and copy the file to a temp folder. That way they always have the latest version if I make changes to the front end. The master file lives in a shared OneDrive folder. The issue I have is that of my users 1 has his OneDrive on his D drive while others have it on their C drive.

Below is my feeble attempt but it does not seem to work.
Welcome to Eleven Forum

Try this at the start of the batch file....

Code:
@echo off
set DRIVE=none
if exist "D:\OneDrive\Eagles_GrandReceiver" set DRIVE=D
if exist "E:\OneDrive\Eagles_GrandReceiver" set DRIVE=E
if %drive% == none echo Drive not found . . .
If %drive% == none pause
If %drive% == none exit
Echo Drive found as %DRIVE%

From this point on wherever you would have used D or E in the batch file you can use %DRIVE% instead.
eg: mkdir %DRIVE%:\FECopy instead of mkdir D:\FECopy
 
Last edited:

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Acer Aspire 3 A315-23
    CPU
    AMD Athlon Silver 3050U
    Memory
    8GB
    Graphics Card(s)
    Radeon Graphics
    Monitor(s) Displays
    laptop screen
    Screen Resolution
    1366x768 native resolution, up to 2560x1440 with Radeon Virtual Super Resolution
    Hard Drives
    1TB Samsung EVO 870 SSD
    Internet Speed
    50 Mbps
    Browser
    Edge, Firefox
    Antivirus
    Defender
    Other Info
    fully 'Windows 11 ready' laptop. Windows 10 C: partition migrated from my old unsupported 'main machine' then upgraded to 11. A test migration ran Insider builds for 2 months. When 11 was released on 5th October it was re-imaged back to 10 and was offered the upgrade in Windows Update on 20th October. Windows Update offered the 22H2 Feature Update on 20th September 2022. It got the 23H2 Feature Update on 4th November 2023 through Windows Update.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Dell Lattitude E4310
    CPU
    Intel® Core™ i5-520M
    Motherboard
    0T6M8G
    Memory
    8GB
    Graphics card(s)
    (integrated graphics) Intel HD Graphics
    Screen Resolution
    1366x768
    Hard Drives
    500GB Crucial MX500 SSD
    Browser
    Firefox, Edge
    Antivirus
    Defender
    Other Info
    unsupported machine: Legacy bios, MBR, TPM 1.2, upgraded from W10 to W11 using W10/W11 hybrid install media workaround. In-place upgrade to 22H2 using ISO and a workaround. Feature Update to 23H2 by manually installing the Enablement Package.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.
Thank you so much. Here is the final code:

Code:
@echo off
set DRIVE=none
if exist " C:\Users\"%USERNAME%"\OneDrive\Eagles\Distribution " set DRIVE=C
if exist "D:\OneDrive\Eagles_GrandReceiver" set DRIVE=D
if %drive% == none echo "Drive not found . . ."
If %drive% == none pause
If %drive% == none exit
Echo Drive found as %DRIVE%
mkdir %DRIVE%:\FECopy_GrandReceiver

DEL %DRIVE%":\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

COPY %DRIVE%:\OneDrive\Eagles_GrandReceiver\Distribution\MasterFile\Eagles_GrandReceiver_Master.accdb "%DRIVE%:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

Start %DRIVE%:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

EXIT /b
 

My Computer

System One

  • OS
    Windows 11
I amended the code just a little bit to remove the file when the database closes.

Is there anything that can be added to the batch file to minimize the cmd.exe window. I do not mind it being on the taskbar but do not want it on the screen.

Code:
@echo off

set DRIVE=none
if exist " C:\Users\"%USERNAME%"\OneDrive\Eagles\Distribution " set DRIVE=C
if exist "D:\OneDrive\Eagles_GrandReceiver" set DRIVE=D
if %drive% == none echo "Drive not found . . ."
If %drive% == none pause
If %drive% == none exit
Echo Drive found as %DRIVE%
mkdir C:\FECopy_GrandReceiver

DEL C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

COPY %DRIVE%:\OneDrive\Eagles_GrandReceiver\Distribution\MasterFile\Eagles_GrandReceiver_Master.accdb "C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

Start /wait C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

DEL C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

EXIT /b
 

My Computer

System One

  • OS
    Windows 11
Is there anything that can be added to the batch file to minimize the cmd.exe window. I do not mind it being on the taskbar but do not want it on the screen.
No, not in the batch file, but if you create a shortcut to run it you can set it to be minimized when you start it from the shortcut. You could put this shortcut in the user's Start Up folder if you want it to run automatically when the sign in.
C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

1663006181596.png

If you are starting it from another script, then you can use the Start command with a /min argument, like this:
start /min c:\temp\test.bat

NB: however you do it, you'll want to remove that PAUSE command if no one is going to be able to see it and respond!
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Acer Aspire 3 A315-23
    CPU
    AMD Athlon Silver 3050U
    Memory
    8GB
    Graphics Card(s)
    Radeon Graphics
    Monitor(s) Displays
    laptop screen
    Screen Resolution
    1366x768 native resolution, up to 2560x1440 with Radeon Virtual Super Resolution
    Hard Drives
    1TB Samsung EVO 870 SSD
    Internet Speed
    50 Mbps
    Browser
    Edge, Firefox
    Antivirus
    Defender
    Other Info
    fully 'Windows 11 ready' laptop. Windows 10 C: partition migrated from my old unsupported 'main machine' then upgraded to 11. A test migration ran Insider builds for 2 months. When 11 was released on 5th October it was re-imaged back to 10 and was offered the upgrade in Windows Update on 20th October. Windows Update offered the 22H2 Feature Update on 20th September 2022. It got the 23H2 Feature Update on 4th November 2023 through Windows Update.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Dell Lattitude E4310
    CPU
    Intel® Core™ i5-520M
    Motherboard
    0T6M8G
    Memory
    8GB
    Graphics card(s)
    (integrated graphics) Intel HD Graphics
    Screen Resolution
    1366x768
    Hard Drives
    500GB Crucial MX500 SSD
    Browser
    Firefox, Edge
    Antivirus
    Defender
    Other Info
    unsupported machine: Legacy bios, MBR, TPM 1.2, upgraded from W10 to W11 using W10/W11 hybrid install media workaround. In-place upgrade to 22H2 using ISO and a workaround. Feature Update to 23H2 by manually installing the Enablement Package.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, supported device running Windows 11 Pro (and all my Hyper-V VMs).

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 256GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro RTM and Insider Beta as native boot vhdx.

    My SYSTEM FIVE is a Dell Latitude 3190 2-in-1, Pentium Silver N5030, 4GB RAM, 512GB NVMe ssd, supported device running Windows 11 Pro, plus the Insider Beta, Dev, and Canary builds as a native boot .vhdx.

Latest Support Threads

Back
Top Bottom