China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 01:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to get the current day of the week in a bat file? View 2,367 Replies 4
Original Poster Posted 2006-09-10 10:45 ·  中国 四川 绵阳 电信
初级用户
Credits 26
Posts 7
Joined 2006-09-06 05:20
19-year member
UID 61942
Gender Male
From 四川
Status Offline
To write an automatic shutdown batch file and get the current day of the week in a batch script to make different shutdown time settings for different days of the week, you can use the following method:

```batch
@echo off
for /f "tokens=2 delims==" %%a in ('wmic os get LocalDateTime /value') do set "dt=%%a"
set "weekday=%dt:~8,2%"
if "%weekday%"=="05" (
echo Today is Friday, execute a.bat
call a.bat
) else if "%weekday%"=="06" (
echo Today is Saturday, execute a.bat
call a.bat
) else (
echo Today is not Friday or Saturday, execute b.bat
call b.bat
)
```

Explanation: First, use `wmic os get LocalDateTime /value` to get the system's date and time information, then extract the day of the week part (`%dt:~8,2%` gets the 9th and 10th characters, which represent the day of the week in the format like "05" for Friday, "06" for Saturday). Then make judgments based on the value of the `weekday` variable, and execute different batch files accordingly.

Please note that the above code is a basic example, and you can adjust it according to your specific actual needs.

[ Last edited by gskys123 on 2006-9-10 at 22:13 ]
Floor 2 Posted 2006-09-11 00:55 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
If you echo %date% shows like: 2006-09-10 Sunday, then the following can

echo %date% |find "Friday" && call a.bat ||call b.bat
echo %date% |find "Saturday" && call a.bat ||call b.bat
Floor 3 Posted 2006-09-11 02:13 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
View Help
HH ntcmds.chm::/net_user.htm




Examples
To display a list of all user accounts on the local computer, type:

net user

To view information about the user account jimmyh, type:

net user jimmyh

To add a user account for Jay Jamison, with logon permissions from Monday to Friday, 8 AM to 5 PM (no spaces in the time specification), and a forced password (jayj) and full name for the user, type:

net user jayj /add /passwordreq:yes /times:monday-friday,8am-5pm/fullname:"Jay Jamison"

To set johnsw's logon time using 24-hour notation (8 AM to 5 PM), type:

net user johnsw /time:M-F,08:00-17:00

To set johnsw's logon time using 12-hour notation (8 AM to 5 PM), type:

net user johnsw /time:M-F,8am-5pm

To specify marysl's logon time as 4 AM to 5 PM on Monday, 1 PM to 3 PM on Tuesday, and 8 AM to 5 PM on Wednesday to Friday, type:

net user marysl /time:M,4am-5pm;T,1pm-3pm;W-F,8:00-17:00
Floor 4 Posted 2006-09-12 02:30 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
In fact, using the day of the week to set different shutdown times is only useful for general users. Anyone with a little computer knowledge knows that you can change the date by entering the BIOS. Unless you also want to set a password for the BIOS.
Floor 5 Posted 2006-09-12 04:17 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Wow, the person upstairs can even think of this trick, I'm impressed

P.S. It seems there's a time synchronization feature in Windows that can be used to prevent the method the person upstairs used

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Forum Jump: