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-06-27 06:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Background execution, automatic shutdown after 30 seconds of booting, cancel task View 1,761 Replies 7
Original Poster Posted 2008-12-14 12:23 ·  中国 黑龙江 牡丹江 电信
新手上路
Credits 0
Posts 2
Joined 2008-12-13 16:12
17-year member
UID 133755
Gender Male
Status Offline
I want to make two scripts.
1. A script that automatically shuts down the computer 30 seconds after startup and runs in the background.
2. A script that can cancel the task.
Thank you, great experts!~!~

adamson148@163.com
If possible, send it to my email! Thank you ha!~

───────────────── Moderation Record ─────────────────
Performed by: HAT
Operation: Added search keywords in the post title
Description: The original title "Seeking scripts!~ Experts come to help quickly ha!~ 3Q啦!~" is not conducive to forum search
Punishment: New forum members are exempt from points punishment
Tip: It is recommended to read the following posts
{1415}The Wisdom of Asking Questions
{7326}Essential Read for New Forum Members, Basic Code of Conduct for Everyone
{22703}Please Don't Be an Impatient Person
{32667}Those Who Can't Even Write a Clear Title, Wake Up
{32825}This Forum Seversely Rectifies Poor Posts
───────────────── Moderation Record ─────────────────


[ Last edited by HAT on 2008-12-14 at 18:02 ]
Floor 2 Posted 2008-12-14 13:30 ·  中国 黑龙江 牡丹江 电信
新手上路
Credits 0
Posts 2
Joined 2008-12-13 16:12
17-year member
UID 133755
Gender Male
Status Offline
Oh, why no one helps? Please, all you experts!~
Floor 3 Posted 2008-12-15 17:01 ·  中国 广东 深圳 电信
初级用户
★★
游手好闲 + 无所事事 ..
Credits 194
Posts 167
Joined 2007-04-30 09:43
19-year member
UID 87022
Gender Male
Status Offline
It's quite simple. It's suggested that you study it by yourself.

You can use ping 127.1 -n 30 to delay for 30 seconds. The precision is general, but it's about the same.

You can use shutdown /f /s to shut down automatically.

To run it hidden in the background, you can search related posts in this forum. Many are implemented with VBS.

To make the task start at boot, you can put it in the startup menu or write the registry run item with reg.

To cancel it, you can use TASKKILL /IM CMD.EXE to directly terminate CMD.

Use your own hands, and you'll have abundant rewards.
Floor 4 Posted 2008-12-15 22:26 ·  中国 湖南 湘潭 电信
初级用户
Credits 61
Posts 45
Joined 2008-07-11 23:33
17-year member
UID 121388
Gender Male
Status Offline
shutdown -s -t 30
shutdown -a
Floor 5 Posted 2008-12-16 11:30 ·  IANA 局域网IP(Private-Use)
初级用户
★★
游手好闲 + 无所事事 ..
Credits 194
Posts 167
Joined 2007-04-30 09:43
19-year member
UID 87022
Gender Male
Status Offline
Originally posted by okzhsh01 at 2008-12-15 10:26 PM:
shutdown -s -t 30
shutdown -a



shutdown -s -t 30
There will be a window prompting for a 30-second shutdown. It is estimated that the original poster wants to achieve a silent shutdown. Otherwise, it wouldn't be so mysterious. Hehe.
Floor 6 Posted 2009-01-05 21:07 ·  中国 广东 广州 天河区 电信
新手上路
Credits 0
Posts 3
Joined 2008-12-16 12:39
17-year member
UID 134036
Gender Male
Status Offline
The points are too low, and many things can't be seen.
Floor 7 Posted 2009-01-05 21:40 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Q: How to get points?
A: You can get points by creating new topics and replying. The specific rules can be viewed at the bottom of each section; excellent new topics and replies may also be awarded points by others; posting water content, reviving old threads, etc. in technical sections may result in points deducted by others.
Floor 8 Posted 2009-01-07 20:25 ·  中国 上海 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
### Previous Attempts to Restrict Student Logins
I once thought about restricting students from turning on their computers, but it didn't work out in the end. Who has the time to sit there doing that every day? Ugh, computer labs without internet are really a hassle.

### Password Change Plan
Our new master disk has two sets of accounts built into each system:
- Username: Administrator, Password: onlyedu, for system management
- Username: Onlyit, Password: empty, for student teaching

This password change plan involves, during break time, the teacher's computer using psexec to remotely execute password changes on all student computers and then lock the student terminals. Students need to go to the office to get the password to log in when they need to use the computer.

Here's a simple example:

**Change Student End Password.cmd**
-----------------------------
for /f "tokens=1,2 delims=/ " %%a in (password.txt) do @psexec \\%%a -u administrator -p onlyedu –c -d run.cmd %%b
-----------------------------

**Run.cmd**
--------------------------------
net user onlyit "%1"
%windir%\System32\rundll32.exe user32.dll,LockWorkStation
----------------------------------

**Password.txt**
------------------------------
192.168.1.3/123456
192.168.1.8/fsdaf
-------------------------------

We use the for syntax to separate the IP part (%a) and the new password part (%b) from the password file password.txt using the "/" delimiter. Then, psexec is used to remotely upload run.cmd to the student terminal to execute `net user onlyit "%1"`, where %1 is the parameter passed from %b. Then, the rundll32 command is used to lock the student terminal. If they want to use the computer, they need to go to the office to get the password.

To avoid file processing troubles, the password.txt should have the IP followed immediately by "/" and then the continuous password, with no blanks. For example, the following are incorrect: one has a space in the password and the other has a blank at the end of the password.
192.168.1.3/12 21
192.168.1.3/12

**Other Notes**
1. Ensure network connectivity; disable the network card or use automatic IP configuration.
2. Remove permissions for lusrmgr.msc, nusrmgr.msc, and corresponding programs for creating new users for the onlyit user.
3. Configure a script to automatically delete any new users created by students.

This is just a simple plan implementation; more details need to be summarized during implementation.


### Scheduled Shutdown Plan
Let's talk about the feasibility of forced scheduled shutdown. I classify this document as top secret, not because it's very sophisticated, but because it's like the saying "once you reveal it, it's not valuable anymore." Because in the earlier attempt to block the Warcraft game using the firewall, some students enabled registry entries and stopped the Windows firewall, making the method ineffective. The scheduled task we're using this time is also an easily bypassed method, so we shouldn't tell anyone else how we implement it unless necessary.

Our steps are: ensure the scheduled task runs during user login, quietly synchronize the system time during class, force a shutdown from 17:15 to 18:15, and allow normal boot in other periods.

1. **Ensure Scheduled Task Service is Running**
First, we load Bschedule.cmd in the group policy user login settings to ensure the scheduled task is running.
**Bschedule.cmd**
---------------------------------
%systemroot%\system32\sc.exe config Schedule start= AUTO
%systemroot%\system32\sc.exe start Schedule
----------------------------------

2. **Common Scheduled Task Types**
MINUTE, minute
HOURLY, hourly
DAILY, daily
WEEKLY, weekly
MONTHLY, monthly
ONCE, once
ONSTART, at startup
ONLOGON, when user logs on
ONIDLE. when idle

3. **Synchronize System Time**
Autosyntime.cmd is used to create an ONIDLE type scheduled task. If necessary, remove the permission for all student computers to change the time. Then, as long as the network is connected, as long as the teacher's computer time is calibrated, all computers will automatically synchronize with the teacher's computer time.
---------------------------------------
SCHTASKS /delete /tn autosyntime /f
SCHTASKS /create /RU onlyit /RP "" /SC ONIDLE /I 1 /TN autosyntime /TR "c:\windows\system32\net.exe time \\teacher /set /y"
-------------------------------------------

4. **Force Shutdown from 17:15 to 18:15**
In the most ideal test method, a plan task of ONLOGON type is generated at 17:15, so that as soon as the user logs in, it will immediately log off. But this method has several drawbacks:
a. It must log in as a user (onlyit).
b. Cannot implement NTFS permissions to achieve hiding in the control panel.
c. Since it's an ONLOGON type, in a single-machine environment, another plan to delete it every minute from 18:16 today to 17:14 tomorrow is needed to ensure normal login. So we give up.

In actual testing, we originally wanted to use the logoff method because in an emergency, the computer is still at the welcome screen and we have other methods to cancel the scheduled task. But the tested shutdown, rundll32, logou and other programs can only be executed normally in the current user state, which means we must use the current logged-in user's account to execute the scheduled task, and we can't control the accounts that students create themselves. So we temporarily use shutdown –s –t 900 –c "Shutdown".


**Forcelogout.cmd** The command line parameters in XP don't meet our needs. The schtasks in XP doesn't support the /ET parameter setting for duration in 2003. Then we can only implement it by copying. So we set a scheduled task named forcelogout that will execute shutdown every minute starting at 17:15:00 every day.
--------------------------
SCHTASKS /delete /tn forcelogout /f
SCHTASKS /create /RU "" /RP onlyedu /SC MINUTE /MO 1 /TN forcelogout /TR " shutdown –s –t 900 –c "Shutdown"" /ST 17:15:00 /SD 2000/01/01
---------------------------

5. **Strengthen Security Settings**
a. Scheduled task service is stopped ^In this case, it can only be ensured remotely through psexec.
b. System time is incorrect (in single-machine case) ^Troublesome, probably only adjusting BIOS time settings.
c. control schedtasks advanced/view log ^hidlog.cmd, deny onlyit user access to scheduled task log
----------------------------------------
sc stop schedule
REM Ping for delay processing to ensure service stops correctly
ping -l -n 4 127.0.0.1>nul
del %systemroot%\schedlgu.txt /q
REM The following two steps ensure schedlgu.txt is generated
sc start schedule
sc stop schedule
REM Then set permissions for schedlgu.txt to deny current user onlyit access
cacls %systemroot%\schedlgu.txt /e /d onlyit
sc start schedule
---------------------------------------------------
d. Forbid viewing scheduled tasks in remote computer shares ^hideschtasks.reg.
---------
Windows Registry Editor Version 5.00


---------
e. Forbid onlyit user access to schtasks command
cacls %systemroot%\system32\schtasks.exe /e /d onlyit
f. Forbid onlyit account from viewing scheduled task settings, which can hide it in the control panel
cacls %systemroot%\tasks\autosyntime.job /e /d onlyit

Let's stop here for now. Everyone also needs to consider how to handle cases like 105 being normal usually but needing to be solved from 13:00 to 21:00 on Sunday, and how to unlock in case of sudden events.


### Better Logoff Plan
The earlier forced offline plan has many inoperable aspects due to shutdown. Its -s forced shutdown can be executed under all users, but if an emergency occurs, even the administrator can't cancel it, and its -l forced logoff also needs to be executed under the logged-in user's account.

This time we use the net user /times parameter to set the user's login time:
net user onlyit "" /times:monday-friday,8AM-5PM,6PM-10PM;saturday-sunday,8AM-10PM

Allowed login hours:
- Sunday: 08:00 AM - 10:00 PM
- Monday: 08:00 AM - 05:00 PM, 06:00 PM - 10:00 PM
- Tuesday: 08:00 AM - 05:00 PM, 06:00 PM - 10:00 PM
- Wednesday: 08:00 AM - 05:00 PM, 06:00 PM - 10:00 PM
- Thursday: 08:00 AM - 05:00 PM, 06:00 PM - 10:00 PM
- Friday: 08:00 AM - 05:00 PM, 06:00 PM - 10:00 PM
- Saturday: 08:00 AM - 10:00 PM

In this way, we have set the specific login periods for the onlyit user each day. For example, on Monday, the user can log in from 08:00 to 17:00 during class time. Then, as long as the user doesn't log off, the student can still use the computer normally after 17:00. Then we need to run a scheduled task at 17:15.

**Lock_workstation.cmd** Lock the console, so that from 17:00 to 18:00, the user can't log in.
SCHTASKS /delete /tn Lock_workstation /f
SCHTASKS /create /RU "" /RP onlyedu /SC MINUTE /MO 1 /TN Lock_workstation /TR "%windir%\System32\rundll32.exe user32.dll,LockWorkStation" /ST 17:15:00 /SD 2000/01/01

The advantage of this compared to the earlier shutdown –l plan is that in this state, we can keep the student's work, but unlocking still requires using psexec to remotely change the time.


### Reference Document
Skillfully Use the net user Command to Restrict User Login to the Computer
Forum Jump: