どのような種類のスパイウェア対策プログラムがインストールされていますか?ホストファイルが変更されないようにするものもあります。このvbscriptは私のために働く。読み取り専用属性を削除し、編集を行い、読み取り専用属性を再適用します。これにはいくつかのコードが繰り返されているため、より適切な機能を持つように修正する必要があります。
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const ReadOnly = 1
strWinDir = WshShell.ExpandEnvironmentStrings("%windir%")
HostsFile = strWinDir & "\System32\drivers\etc\hosts"
Set objFile = objFSO.GetFile(HostsFile)
If objFile.Attributes AND ReadOnly Then
objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
Set objFile = objFSO.OpenTextFile(HostsFile, ForAppending)
objFile.WriteLine(vbNewLine & "127.0.0.1 www.google.lk")
objFile.Close
Set objFile = objFSO.GetFile(HostsFile)
If Not objFile.Attributes AND ReadOnly Then
objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
同じ文字列を削除するコード。
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const ReadOnly = 1
strWinDir = WshShell.ExpandEnvironmentStrings("%windir%")
HostsFile = strWinDir & "\System32\drivers\etc\hosts"
Set objFile = objFSO.GetFile(HostsFile)
If objFile.Attributes AND ReadOnly Then
objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
Set objFile = objFSO.OpenTextFile(HostsFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, "127.0.0.1 www.google.lk") = 0 Then
strContents = strContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(HostsFile, ForWriting)
objFile.Write strContents
objFile.Close
Set objFile = objFSO.GetFile(HostsFile)
If Not objFile.Attributes AND ReadOnly Then
objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
こんにちはYohanさん、よろしくお願いします。実際に '"'を使用しているのでしょうか、実際にそれらの場所に普通の普通の二重引用符 '' 'がありますか? –
ただ、' '' @Vince Bowdren –