Solved exit bat file


junieman

Active member
Local time
2:20 PM
Posts
42
OS
windows 11 pro
I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
 

My Computer

System One

  • OS
    windows 11 pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    dell
    CPU
    intel core i7-11700f
    Memory
    12 gb
    Monitor(s) Displays
    3
    Hard Drives
    256
    Keyboard
    wireless
    Mouse
    wireless
    Internet Speed
    50 mb
In the most general terms, you'd have to look for the DAY-DATA at the very first of the batch file and if it were Saturday or Sunday, then jump to END.
I've written b'zillions of batch files over the past 40 years or so, but I've never done exactly what you want to do.

I do believe it's possible to do what you want in DOS Batch File language, even though I can't give you the exact Syntax.

Good Luck,
TM :cool:
 

My Computer

I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
This might help

 

My Computer

System One

  • OS
    Windows 11 Pro + Win11 Canary VM.
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Zenbook 14
    CPU
    I9 13th gen i9-13900H 2.60 GHZ
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB soldered
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    laptop OLED screen
    Screen Resolution
    2880x1800 touchscreen
    Hard Drives
    1 TB NVME SSD (only weakness is only one slot)
    PSU
    Internal + 65W thunderbolt USB4 charger
    Case
    Yep, got one
    Cooling
    Stella Artois (UK pint cans - 568 ml) - extra cost.
    Keyboard
    Built in UK keybd
    Mouse
    Bluetooth , wireless dongled, wired
    Internet Speed
    900 mbs (ethernet), wifi 6 typical 350-450 mb/s both up and down
    Browser
    Edge
    Antivirus
    Defender
    Other Info
    TPM 2.0, 2xUSB4 thunderbolt, 1xUsb3 (usb a), 1xUsb-c, hdmi out, 3.5 mm audio out/in combo, ASUS backlit trackpad (inc. switchable number pad)

    Macrium Reflect Home V8
    Office 365 Family (6 users each 1TB onedrive space)
    Hyper-V (a vm runs almost as fast as my older laptop)
I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
Why not open Task Scheduler and Create a Task to run the batch file? In the settings for the Task, you can specify Monday to Friday (or NOT saturday or Sunday), and it will run at the time you set M-F, but not on Sa Su.
 

My Computers

System One System Two

  • OS
    11 Pro 24H2 26100.2454
    Computer type
    PC/Desktop
    Manufacturer/Model
    Lenovo ThinkCentre M920S SFF
    CPU
    i7-9700 @ 3.00GHz
    Motherboard
    Lenovo 3132
    Memory
    32GBDDR4 @ 2666MHz
    Graphics Card(s)
    Intel HD 630 Graphics onboard
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    LG E2442
    Screen Resolution
    1920x1080
    Hard Drives
    1 x Samsung 970 EVO PLUS 500GB NVMe SSD, 1 x WD_BLACK SN770
    250GB NVMe SSD (OS and programs), 1 x WD_BLACK SN770
    500GB NVMe SSD (Data)
    Case
    Lenovo SFF
    Keyboard
    Cherry Stream TKL JK-8600US-2 Wired
    Mouse
    LogiTech M510 wireless
    Internet Speed
    Fast (for fixed wireless!)
    Browser
    Chrome, sometimes Firefox
    Antivirus
    Malwarebytes Premium & Defender (working together beautifully!)
  • Operating System
    11 Pro 24H2 26100.2454
    Computer type
    PC/Desktop
    Manufacturer/Model
    Lenovo ThinkCentre M920S SFF
    CPU
    i5-8400 @ 2.80GHz
    Motherboard
    Lenovo 3132
    Memory
    32GB DDR4 @ 2600MHz
    Graphics card(s)
    Intel HD 630 Graphics onboard
    Sound Card
    Realtek High Definition Audio onboard
    Monitor(s) Displays
    LG FULL HD (1920x1080@59Hz)
    Screen Resolution
    1920 x 1080
    Hard Drives
    1 x Samsung 970 EVO PLUS NVMe; 1 x Samsung 980 NVMe SSD
    Case
    Lenovo Think Centre SFF
    Mouse
    LogiTech M510 wireless
    Keyboard
    Cherry Stream TKL JK-8600US-2 Wired
    Internet Speed
    Fast (for fixed wireless!)
    Browser
    Chrome
    Antivirus
    Malwarebytes Premium and MS Defender, beautiful together
PowerShell can return DayofWeek as an integer.
0 = Sunday
1 = Monday
6 = Saturday

Code:
@echo off
powershell -nop "if ([int](Get-Date).DayOfWeek -le 1) { exit 1 }"

if %ERRORLEVEL% EQU 1 (
    @echo script exit
) else (
    @echo script continue
)
 

My Computer

System One

  • OS
    Windows 7
if yesterday's date = SUNDAY OR SATURDAY.
is that the same as todays date = Monday or Sunday
 

My Computers

System One System Two

  • OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i5-9400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
Garlin,

Works great, thanks for the help.
 

My Computer

System One

  • OS
    windows 11 pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    dell
    CPU
    intel core i7-11700f
    Memory
    12 gb
    Monitor(s) Displays
    3
    Hard Drives
    256
    Keyboard
    wireless
    Mouse
    wireless
    Internet Speed
    50 mb
This would be a batch way to do it, but I'm a PowerShell person myself.
Batch:
for /f %%a in ('date /t') do (
if "%%a" NEQ "Mon" (
  if "%%a" NEQ "Sat" (
    echo do something here
  )
)
)
 

My Computer

System One

  • OS
    Windows 11 Pro 24H2 [rev. 4351]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender

Latest Support Threads

Back
Top Bottom