VBS script implementation modifies DNS and empties the IE temporary files feature _vbs

Source: Internet
Author: User

This morning received the telephone, said that need a change DNS for school DNS, and empty IE temporary files script, don't want to, with batch write a:

Copy Code code as follows:

REM programed by Kaisir
@echo off
The function of the echo script is to modify your DNS for the Shandong Youth Political college dedicated DNS 222.194.76.2 also helps you clean up temporary files on your computer. If you have any questions, please call the Network Center.
Pause
echo Modifies DNS ...
netsh interface ip set DNS "Local Area Connection" Source=static addr=222.194.76.2
Echo DNS has been successfully modified and will then begin emptying ie temporary files ...
Pause
echo Clears temporary file ...
del/f/s/q "%userprofile%local settingstemporary Internet files*.*"
del/f/s/q "%userprofile%appdatalocalmicrosoftwindowstemporary Internet files*.*"
Echo full operation completed successfully! Thank you for your use.
Pause

You see, the idea is very simple, with Netsh to change the DNS is, because to adapt to Win7 and XP temporary directory, so the deletion of the statement wrote two times.

But, to think about it, this script has a lot of problems,

1 if the user has more than one network card, this script will only modify the "local connection" that.

2 If the user has manually modified the location of the temporary file, then this script can not be powerless.

So, here's the script for the VBS version.

Copy Code code as follows:

' Delete all files and folders under 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 executed successfully!")
Else
End If

This is more intelligent, through the winmgmts to get a list of network cards in the system, and then traverse the enabled network card, and then modify. The Temporary Files section is also used to get the folder location by reading the key value of the registry "Hkcusoftwaremicrosoftwindowscurrentversionexplorershell Folderscache" entry. And then kill him by the corresponding method of the FSO object created

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.