Skip to content

Instantly share code, notes, and snippets.

@mkp246
Last active January 11, 2019 05:55
Show Gist options
  • Save mkp246/52a0be863cfb6c764f7e8c1e904e6440 to your computer and use it in GitHub Desktop.
Save mkp246/52a0be863cfb6c764f7e8c1e904e6440 to your computer and use it in GitHub Desktop.
If you are using office Laptop and don't want to run office specific programs at startup when you are outside of office time or weekend
@echo off
setlocal enableextensions enabledelayedexpansion
SETLOCAL
set ctime=%time: =0%
set inoffice=y
if "%ctime%" lss "09:00:00,00" ( set "inoffice=" )
if "%ctime%" geq "18:00:00,00" ( set "inoffice=" )
for /F "skip=2 tokens=2-4 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set daynumber=%%A
if /I %daynumber% EQU 6 set notofficeday=y
if /I %daynumber% EQU 0 set notofficeday=y
if defined inoffice if not defined notofficeday (
choice /C YN /T 10 /D Y /M "Press N to abort in 10 seconds"
if !ERRORLEVEL! EQU 2 goto endoffile
echo Starting Apps....
cd %~dp0*
for /f %%i in ('dir /b *.lnk') do %%i
) else (
echo You Are Not In Office Enjoy
)
ENDLOCAL
:endoffile
REM pause
@mkp246
Copy link
Author

mkp246 commented Mar 19, 2017

Usage:
put this file in startup folder (RUN> shell:startup) with all .lnk to start.
OR
put it in folder with all .lnk to start and put .lnk for this batch script in startup folder.
Configuration
at line 6 and 7 configure office start and end time.
at line 20 more programs can be added. BY default all shortcuts( .lnk files ) are started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment