SendMessage, спасибо, ясно. Ну, дык, есть же свойство «.Attributes», есть DeleteFile с параметром Force — какие проблемы.
streamrider, примерно так:
читать дальше »
Код:

Option Explicit
Const strFileName = "hosts"
Const SystemFolder = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strPath
Dim strFullFileName
Dim strNewFullFileName
With WScript.CreateObject("Scripting.FileSystemObject")
If WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer(".", "root\default").Get("StdRegProv").GetStringValue( _
HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "DataBasePath", strPath) = 0 Then
WScript.Echo "Found parameter [DataBasePath]"
Else
strPath = .BuildPath(.GetSpecialFolder(1).Path, "drivers\etc")
WScript.Echo "Can't found parameter [DataBasePath], try default path as [" & strPath & "]"
End If
strFullFileName = .BuildPath(strPath, strFileName)
strNewFullFileName = .BuildPath(.GetParentFolderName(WScript.ScriptFullName), strFileName)
If .FileExists(strFullFileName) Then
If .FileExists(strNewFullFileName) Then
.DeleteFile strNewFullFileName, True
End If
.CopyFile strFullFileName, strNewFullFileName, True
If .FileExists(strNewFullFileName) Then
WScript.Echo "Found [" & strFullFileName & "] and copied to [" & strNewFullFileName & "]"
Else
WScript.Echo "Found [" & strFullFileName & "] but can't copy to [" & strNewFullFileName & "]"
End If
Else
WScript.Echo "File [" & strFullFileName & "] not found"
End If
End With
WScript.Quit 0