你瞧,思路很簡(jiǎn)單,用netsh把dns改了就是了,因?yàn)橐m應(yīng)Win7跟Xp臨時(shí)目錄的不同,于是刪除語(yǔ)句寫了兩遍。
'刪除目錄下的所有文件及文件夾
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("所有操作已成功執(zhí)行!")
else
end if
這個(gè)就比較智能了,通過winmgmts獲取系統(tǒng)中的網(wǎng)卡列表,然后遍歷啟用的網(wǎng)卡,然后進(jìn)行修改。而臨時(shí)文件部分,也是通過讀取注冊(cè)表“HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folderscache”項(xiàng)的鍵值來(lái)獲取文件夾位置。之后通過創(chuàng)建的fso對(duì)象的相應(yīng)方法給他干掉~