Vbs script realizes the functions of modifying DNS and emptying ie temporary files

Time:2021-12-31

I received a call from Shanqing hospital this morning, saying that I need a script to modify DNS to campus DNS and empty ie temporary files. Without thinking about it, I wrote a batch:

 

Copy codeThe code is as follows:

rem programed by Kaisir
@echo off
Echo the role of this script is to modify your DNS to the special DNS 222.194 of Shandong Youth Political College 76.2 at the same time, it helps you clear the temporary files in your computer. If you have any questions, please call the network center.
pause
Echo modify DNS
Netsh interface IP set DNS “local connection” source = static addr = 222.194 seventy-six point two
Echo DNS has been modified successfully. Next, we will start emptying ie temporary files
pause
Echo clear temporary files
del /f /s /q “%userprofile%Local SettingsTemporary Internet Files*.*”
del /f /s /q “%userprofile%AppDataLocalMicrosoftWindowsTemporary Internet Files*.*”
Echo all operations have been completed successfully! Thank you for your use.
pause

 

You see, the idea is very simple. Just change DNS with Netsh. To adapt to the difference between win7 and XP temporary directories, the deletion statement is written twice.

But when you think about it, there are many problems with this script,

1) If the user has multiple network cards, this script will only modify the one of “local connection”.

2) If the user manually changes the location of the temporary file, there is nothing this script can do.

So, with the following VBS version of the script.

 

Copy codeThe code is as follows:


‘delete all files and folders in the directory
 Const DeleteReadOnly = True
 Set objFSO = CreateObject(“Scripting.FileSystemObject”)
  objFSO.DeleteFile(net_temp&”*.*”), DeleteReadOnly
 strComputer = “.”
 Set objWMIService = GetObject(“winmgmts:” & strComputer & “rootcimv2”)
 Set colSubfolders2 = objWMIService.ExecQuery _
        (“Associators of {Win32_Directory.Name='” & net_temp & “‘} ” _
            & “Where AssocClass = Win32_Subdirectory ” _
                & “ResultRole = PartComponent”)

 

    For Each objFolder2 in colSubfolders2
        objFSO.deleteFolder objFolder2.name , DeleteReadOnly
    Next
Msgbox (“all operations performed successfully!”)
else
end if

 

This is more intelligent. Get the list of network cards in the system through winmgmts, then traverse the enabled network cards, and then modify them. The temporary file part also obtains the folder location by reading the key value of the “hkcusoftware Microsoft Windows current version Explorer shell foldercache” key in the registry. Then kill him through the corresponding method of the created FSO object~

Recommended Today

Use vite to build vue3.0+ts+element plus+sass project

Installing the vite environment yarn create @vitejs/app Initialize vue+ts items with vite yarn create @vitejs/app project-name Project name, enter Select ‘Vue’ and enter Select ‘Vue ts’ enter complete Follow the steps to follow the prompts in the above figure cd project-name yarn yarn dev Run successfully Configure host vite.config.tsConfigure host and alias import { defineConfig […]