Usuário com melhor resposta
Não excluir arquivo especifico

Pergunta
-
Olá.
Tenho esse script em bat. Porém, não sei se dar pra fazer isso por bat. Quero excluir todos arquivos .COM da raiz mas não quero excluir o arquivo NTDETECT.COM. Nesse script vi como opção a mover o arquivo para outra pasta e depois trazer de volta. Tem como fazer a remoção de todos os arquivos .COM mas dizer para não excluir NTDETECT.COM?
Abs.
Felipe
echo seta tipo de inicializacao
sc config wuauserv start= auto
sc config bits start= auto
sc config eventlog start= autoecho iniciar servico
net start bits
net start eventlog
net start wuauservattrib -R -H -S %SystemDrive%\NTDETECT.COM
echo mover para destino %SystemDrive%\windows
move %SystemDrive%\autoexec.bat %systemroot%
move %SystemDrive%\NTDETECT.COM %systemroot%echo deletar arquivos
del /a /f %SystemDrive%\*.bat
del /a /f %SystemDrive%\*.com
del /a /f %SystemDrive%\*.exe
del /a /f %SystemDrive%\*.cmd
del /a /f "%SystemDrive%\autorun.inf" /yecho criar arquivo e criar atributo
md %SystemDrive%\autorun.inf
attrib +R +H %SystemDrive%\autorun.infecho mover para origem
move %systemroot%\autoexec.bat %SystemDrive%\
move %systemroot%\NTDETECT.COM %SystemDrive%\echo adicionar chave newsid
reg delete "HKEY_CURRENT_USER\Software\Sysinternals\NewSID" /f
reg add "HKEY_CURRENT_USER\Software\Sysinternals\NewSID" /v EulaAccepted /t REG_DWORD /d 1attrib +R +H +S %SystemDrive%\NTDETECT.COM
echo script executado >\\servidor\compartilhamento\%computername%_%username%.txt
Fidelis
Respostas
-
Segue um vbs que esta funcionando, porem testei em um outro diretorio e nao no C:\ raiz. É só definir o diretorio na variavel sDirPath
--------------------------------------------------------------------------------------------------
Option Explicit
on error resume next
Dim sDirPath'Mudar diretorio conforme necessidade
'Pode-se colocar caminhos UNC \\Server\Share
' Abaixo foi colocado no C:\ mas pode ser usado em qualquer pasta como raiz - > c:\tempsDirPath = "C:\"
Dim oFSO
Dim oFolder
Dim oFileCollection
Dim oFile
Dim oFolderCollectionSet oFSO = CreateObject("Scripting.FileSystemObject")
set oFolder = oFSO.GetFolder(sDirPath)
set oFileCollection = oFolder.FilesFor each oFile in oFileCollection
WScript.Echo oFile.Name
If oFile.Name = "NTDETECT.COM" Then
' WScript.echo "pula"
Else
Select Case Right(oFile.Name, 3)
Case "com"
oFile.Delete(True)
Case "bat"
oFile.Delete(True)
Case "exe"
oFile.Delete(True)
Case "cmc"
oFile.Delete(True)
End Select
End IfNext
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
set oFolderCollection = Nothing
set oSubFolder = Nothing- Marcado como Resposta Fábio JrModerator quarta-feira, 30 de maio de 2012 13:35
Todas as Respostas
-
Boa Tarde,fiz um .vbs aqui.. Teste em um ambiente de teste e diga se funcionou...abs..strComputer = "."dim verificaverifica = ""arquivoprotegido = "NTDETECT.COM"Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set FileList = objWMIService.ExecQuery _("ASSOCIATORS OF {Win32_Directory.Name='C:\'} Where " _& "ResultClass = CIM_DataFile")For Each objFile In FileListverifica = objFile.FileName & "." & objFile.Extensionif verifica = "autorun.inf" thenobjFile.Deleteend ifIf arquivoprotegido = verifica then'wscript.echo pulaElseIf objFile.Extension = "com" ThenobjFile.DeleteEnd IfIf objFile.Extension = "bat" ThenobjFile.DeleteEnd IfIf objFile.Extension = "exe" ThenobjFile.DeleteEnd IfIf objFile.Extension = "cmc" ThenobjFile.DeleteEnd IfEnd IfNext
Eduardo Trombini MCTS - 2008 network infraestructure MCP - 2003 -
-
Olá,
Faça os testes no script abaixo:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Coloque aqui a pasta que será verificada
strPasta = "C:\"
'Coloque aqui os tipos de arquivos que serão copiados ou deletados, separados por ";"
arrTipos = "bat;com;exe;cmd"
arrTipos = split(arrTipos,";")
strExcluido = "ntdetect.com"
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" &strPasta& "'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
For Each tipo in arrTipos
If objFile.Extension = tipo Then
if MID(UCASE(objFile.Name),4,Len(objFile.Name)) <> UCASE(strExcluido) Then
objFile.Delete
End if
End If
Next
Next
Até mais,
Jesiel
Obs.: Se útil, classifique
-
Segue um vbs que esta funcionando, porem testei em um outro diretorio e nao no C:\ raiz. É só definir o diretorio na variavel sDirPath
--------------------------------------------------------------------------------------------------
Option Explicit
on error resume next
Dim sDirPath'Mudar diretorio conforme necessidade
'Pode-se colocar caminhos UNC \\Server\Share
' Abaixo foi colocado no C:\ mas pode ser usado em qualquer pasta como raiz - > c:\tempsDirPath = "C:\"
Dim oFSO
Dim oFolder
Dim oFileCollection
Dim oFile
Dim oFolderCollectionSet oFSO = CreateObject("Scripting.FileSystemObject")
set oFolder = oFSO.GetFolder(sDirPath)
set oFileCollection = oFolder.FilesFor each oFile in oFileCollection
WScript.Echo oFile.Name
If oFile.Name = "NTDETECT.COM" Then
' WScript.echo "pula"
Else
Select Case Right(oFile.Name, 3)
Case "com"
oFile.Delete(True)
Case "bat"
oFile.Delete(True)
Case "exe"
oFile.Delete(True)
Case "cmc"
oFile.Delete(True)
End Select
End IfNext
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
set oFolderCollection = Nothing
set oSubFolder = Nothing- Marcado como Resposta Fábio JrModerator quarta-feira, 30 de maio de 2012 13:35