The above experts' registry solutions are feasible, but not what I most want. I haven't got what I most want yet. After more than a day of my little by little exploration, I finally found the solution I want. Here, I, the younger brother, would like to announce my exploration process to everyone for everyone's study. Please give your advice if there is anything wrong.
Recently I'm learning batch processing and am very interested in it, so I insist on making it realize my idea.
I want this program to stay in memory and monitor the existence of files like qqgame.exe at any time. If there is any, delete it immediately. At first, I thought the directory was on drive C.
The command used is:
@echo off
if exist c:\"program files"\tencent\qqgame\qqgame.exe del c:\"program files\tencent\qqgame\qqgame.exe
(That pair of double quotes was what I just thought of after fumbling for a long time. Without them, it would keep prompting: The system cannot find the path. I was depressed for a long time. Could it be that the directory level is too much? Then I did an experiment on drive D. As a result, no matter how many directories there are, the path can be found. Suddenly I remembered that "programe files" is two words. Is it because of this? First I added single quotes, it didn't work. Then I added double quotes, it worked. I was very happy)
Although this works, there are two problems: one is that it is not monitoring at any time, and the other is that the directory is determined too rigidly. It won't work if the directory is changed.
To improve it, I also used the for command:
@echo off
for %%1 in (c: d:) do @del %%1\qqgame*.* /s /a
I thought about how to execute this command all the time. I thought of looping again and used the following command:
@echo off
:zhang
for %%1 in (c: d:) do @del %%1\qqgame*.* /s /a
goto zhang
Then I executed it on my computer
Oh my god, my CPU was used up by it. That won't do. It's an infinite loop. I have to change another way.
I also thought about being able to make for %%1 in (c: d:) do @del %%1\qqgame*.* /s /a execute regularly. Then the CPU can have a rest.
I thought of the at command. I checked with at /? and then my hope was gone. Its minimum unit is day. I can't execute it once a day. Forget it. Change again.
I used help to see if there were other good commands.
Finally I found the schtasks command. This command should be unique to Windows 2003. Other systems seem not to have it. Its use is really too powerful. It is hundreds of times stronger than at. The following is a little information attached:
Schtasks
Arrange commands and programs to run regularly or at a specified time. Add tasks to the plan, delete tasks from it, start and stop tasks as needed, and display and change scheduled tasks.
To view the command syntax, click the following commands:
? schtasks create
? schtasks change
? schtasks run
? schtasks end
? schtasks delete
? schtasks query
schtasks create
Schedule a task.
Schtasks uses different parameter combinations for various schedule types. To view the combined syntax for creating a task or to view the syntax for creating a task using a specific schedule type, click one of the following options.
? Combined syntax and parameter description
? The scheduled task runs every N minutes
? The scheduled task runs every N hours
? The scheduled task runs every N days
? The scheduled task runs every N weeks
? The scheduled task runs every N months
? The scheduled task runs on specified days of the week
? The scheduled task runs on the specified week of the month
? The scheduled task runs on a specific date of the month
? The scheduled task runs on the last day of the month
? The scheduled task runs once
? The scheduled task runs every time the system starts
? The scheduled task runs when the user logs on
? The scheduled task runs when the system is idle
? The scheduled task runs now
? The scheduled task runs with different permissions
? The scheduled task runs with system permissions
? The scheduled task runs multiple programs
? The scheduled task runs on a remote computer
Combined syntax and parameter description
Syntax
Schtasks /create /sc ScheduleType /tn TaskName /tr TaskRun User ]] User | System}] | *] ] ]
After reading for a long time, I used the following command:
schtasks /create /u Username /p Password /sc minute /mo 1 /tn "Immediate Deletion" /tr d:\a.bat
The content of a.bat is:
@echo off
for %%1 in (c: d:) do @del %%1\qqgame*.* /s /a
It seemed to work, but I also had a requirement. Its minimum interval time is 1 minute. I think it's too long. I want it to execute once every 15 seconds. Let's put this aside first. I looked for it again.
I also checked for a while and found the /t parameter in the choice command. The function of /t is the number of seconds to pause before making the default selection. Its unit is seconds. This is exactly what I want. Ha ha, the opportunity came. I thought of the following command:
@echo off
:zhang
for %%1 in (c: d:) do @del %%1\qqgame*.* /s /a
choice /t 15 /d y
goto zhang
I saved it as a.bat
After opening it, I found it was a window and couldn't disappear. I wanted it to run in the background. I looked for relevant information. I thought that using a vbs script was good. Then I wrote the following script:
set ws=WScript.CreateObject("WScript.Shell")
ws.Run "d:\a.bat",0
Saved as b.vbs
Then I ran it again. Ha ha, it succeeded. It runs in the background. It checks whether there are files like qqgame*.* in the machine every 15 seconds. If there are, it deletes them immediately. Finally my wish was realized.
Later I searched on the Internet and found another method. I didn't try it. I don't know if it works:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a next_hour=0
set /a next_minute=0
for /F tokens=1,2 delims=: %%i in (TIME /T) do (
rem Here 1 is the interval time, you can adjust it yourself as needed
set /a next_minute=%%j+1
set /a next_hour=%%i
if !next_minute! GEQ 60 (
set /a next_minute=!next_minute!-60
set /a next_hour=!next_hour!+1
if !next_hour! GEQ 24 set /a next_hour=!next_hour!-24
)
)
at !next_hour!:!next_minute! c:\settimerun.bat
rem Here is the specific command to be executed, you can adjust it yourself as needed
copy c:\windows\system32\notepad.exe d:\notepad.exe
endlocal
@echo on