bsharath
asked on
Need to delete files from all machines in the file.
Hi,
I have Sophos Antivirus which detect Malware and unwanted files but i have set it not to delete any as i first need to vaalidate then delete it manually.
So i want a way that a script can delete any file in the txt file and all machines whose names are in the txt file.
I will have the files in this format
E:
C:\windows\system32\filena me
So the script has to take the machine names from the txt file and search for any available path or file if there then delete the file.
No matter with what application it is shared with.Needs to kill the process or stop service and delete the file.
Any help..
Regards
SHarath
I have Sophos Antivirus which detect Malware and unwanted files but i have set it not to delete any as i first need to vaalidate then delete it manually.
So i want a way that a script can delete any file in the txt file and all machines whose names are in the txt file.
I will have the files in this format
E:
C:\windows\system32\filena
So the script has to take the machine names from the txt file and search for any available path or file if there then delete the file.
No matter with what application it is shared with.Needs to kill the process or stop service and delete the file.
Any help..
Regards
SHarath
Sharath, if you're running this code:
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
and you're not seeing
"<processnmae> is running."
in your DOS prompt, then there will be another process holding onto the file. I'll have a look at a few tools and see if I can find out what has a file open....
Regards,
Rob.
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
and you're not seeing
"<processnmae> is running."
in your DOS prompt, then there will be another process holding onto the file. I'll have a look at a few tools and see if I can find out what has a file open....
Regards,
Rob.
ASKER
Thats the only message that i get
ASKER
Just a reminder ....
Sharath, please try this....I haven't tested it yet.
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strCommand = "TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "ProcessHold.txt"
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(Replac e(WScript. ScriptFull Name, WScript.ScriptName, "") & "ProcessHold.txt", intForReading, False)
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read Line, 28))
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
objFSO.DeleteFile Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "ProcessHold.txt", True
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strCommand = "TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & Replace(WScript.ScriptFull
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(Replac
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
objFSO.DeleteFile Replace(WScript.ScriptFull
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
ASKER
I get this Rob..
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(50, 31) Microsoft VBScript runtime err
or: File not found
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(50, 31) Microsoft VBScript runtime err
or: File not found
Ha ha, that's what I get for not testing....please try this:
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "ProcHold.txt"
Set objOutputFile = objFSO.CreateTextFile(strP rocHoldFil e, True)
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold File).Shor tPath
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro cHoldFile, intForReading, False)
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read Line, 28))
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
objFSO.DeleteFile strProcHoldFile, True
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards
Rob.
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull
Set objOutputFile = objFSO.CreateTextFile(strP
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
objFSO.DeleteFile strProcHoldFile, True
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards
Rob.
ASKER
Rob just to clarify...
If i have 10 machines in "Computers.txt" and 5 file paths in the other txt file.
The script will scan each file path with all the machines and if found in any machine will delete it.
Am i right?
If there is any process holding it then it will kill the process.
If i have 10 machines in "Computers.txt" and 5 file paths in the other txt file.
The script will scan each file path with all the machines and if found in any machine will delete it.
Am i right?
If there is any process holding it then it will kill the process.
Yes, in theory (hopefully)! I can't guarantee that it will be able to kill the processes, but it should find whatever program is holding onto that particular file, and (hopefully) kill the process, then delete the file...
Rob.
Rob.
ASKER
ANy help with the excel part Rob...
ASKER
Rob any help with these Q's if possible.
https://www.experts-exchange.com/questions/22880964/Script-to-add-the-currently-logged-in-user-as-administrator.html
https://www.experts-exchange.com/questions/22862306/Is-there-any-way-we-can-schedule-events-to-alerts.html
https://www.experts-exchange.com/questions/22878846/How-can-i-get-the-list-of-mailboxes-according-to-the-storage-and-the-machine-names-the-users-have-logged-in.html
https://www.experts-exchange.com/questions/22881184/Get-a-mail-when-a-user-loggs-in.html
https://www.experts-exchange.com/questions/22881407/Script-that-pings-machines-in-a-file-and-send-a-mail-when-Timedout-or-Pinging.html
https://www.experts-exchange.com/questions/22883967/Is-there-a-way-to-keep-a-log-on-all-folders-shared-folders-accesses-in-a-machine-No-Auditing.html
https://www.experts-exchange.com/questions/22880964/Script-to-add-the-currently-logged-in-user-as-administrator.html
https://www.experts-exchange.com/questions/22862306/Is-there-any-way-we-can-schedule-events-to-alerts.html
https://www.experts-exchange.com/questions/22878846/How-can-i-get-the-list-of-mailboxes-according-to-the-storage-and-the-machine-names-the-users-have-logged-in.html
https://www.experts-exchange.com/questions/22881184/Get-a-mail-when-a-user-loggs-in.html
https://www.experts-exchange.com/questions/22881407/Script-that-pings-machines-in-a-file-and-send-a-mail-when-Timedout-or-Pinging.html
https://www.experts-exchange.com/questions/22883967/Is-there-a-way-to-keep-a-log-on-all-folders-shared-folders-accesses-in-a-machine-No-Auditing.html
ASKER
I get this...
C:\WINDOWS\inf\Other.exe does not exist on DEV-CHEN-PC1152
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(49, 31) Microsoft VBScript runtime err
or: Permission denied
I have 250 machines and 80 files .
I get the above message in the 5th machine
C:\WINDOWS\inf\Other.exe does not exist on DEV-CHEN-PC1152
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(49, 31) Microsoft VBScript runtime err
or: Permission denied
I have 250 machines and 80 files .
I get the above message in the 5th machine
Sharath, above this line:
Set objOutputFile = objFSO.CreateTextFile(strP rocHoldFil e, True)
please put this line
If objFSO.FileExists(strProcH oldFile) = True Then objFSO.DeleteFile strProcHoldFile, True
It seems very strange that it can't create "ProcHold.txt" in the same folder that the script is run from....
Regards,
Rob.
Set objOutputFile = objFSO.CreateTextFile(strP
please put this line
If objFSO.FileExists(strProcH
It seems very strange that it can't create "ProcHold.txt" in the same folder that the script is run from....
Regards,
Rob.
ASKER
It gets stuck ar this point.Say fom 10min its the same...
D:\\Lor\data\x\xxafaaaa.a\ psexec.exe does not exist on DEV-CHEN-PC748
Checking if any other process has a handle on this file.
D:\\Lor\data\x\xxafaaaa.a\
Checking if any other process has a handle on this file.
ASKER
Sorry to do this but just eager if you can help...
https://www.experts-exchange.com/questions/22863160/Need-to-change-the-sessions-tab-for-all-users-in-the-file.html
https://www.experts-exchange.com/questions/22884372/Script-that-can-find-all-machines-that-are-created-today-Added-to-the-Domain.html
https://www.experts-exchange.com/questions/22883908/How-can-remotely-say-that-this-machine-only-this-user-can-access-remotely-or-console.html
https://www.experts-exchange.com/questions/22864808/Any-way-to-Query-the-Ads-Users-properties-for-Mailbox-Rights.html
https://www.experts-exchange.com/questions/22883329/Any-way-to-find-where-all-the-Domain-Administrator-is-connectd-and-from-which-machine-has-one-taken-Mstsc.html
https://www.experts-exchange.com/questions/22863160/Need-to-change-the-sessions-tab-for-all-users-in-the-file.html
https://www.experts-exchange.com/questions/22884372/Script-that-can-find-all-machines-that-are-created-today-Added-to-the-Domain.html
https://www.experts-exchange.com/questions/22883908/How-can-remotely-say-that-this-machine-only-this-user-can-access-remotely-or-console.html
https://www.experts-exchange.com/questions/22864808/Any-way-to-Query-the-Ads-Users-properties-for-Mailbox-Rights.html
https://www.experts-exchange.com/questions/22883329/Any-way-to-find-where-all-the-Domain-Administrator-is-connectd-and-from-which-machine-has-one-taken-Mstsc.html
ASKER
I just tried deleted the file and then ran the script i get this...
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(49, 51) Microsoft VBScript runtime err
or: Permission denied
Checking if any other process has a handle on this file.
C:\Delete all files from all computes.vbs(49, 51) Microsoft VBScript runtime err
or: Permission denied
Sharath, that's really strange.....that line where you get the error only deletes the temporary ProcHold.txt file:
If objFSO.FileExists(strProcH oldFile) = True Then objFSO.DeleteFile strProcHoldFile, True
try commenting it out and see the next line automatically overwrites it anyway....
Regards,
Rob.
If objFSO.FileExists(strProcH
try commenting it out and see the next line automatically overwrites it anyway....
Regards,
Rob.
ASKER
Rob i have noticed that Findstr.exe is holding the "Prohold.txt" file thats the reason the script is not able to remove it .I guess...
ASKER
I tried Commenting it and i get this now...
C:\Delete all files from all computes.vbs(50, 31) Microsoft VBScript runtime error: Permission denied
C:\Delete all files from all computes.vbs(50, 31) Microsoft VBScript runtime error: Permission denied
Ah, right....yeah, the new error would be for the same reason then....it's trying to delete / create a file that already has a lock on it. Try this, it should continue to try to delete the file every second....
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "ProcHold.txt"
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
While Err.Number <> 0 Then
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
Wend
Err.Clear
On Error GoTo 0
End If
Set objOutputFile = objFSO.CreateTextFile(strP rocHoldFil e, True)
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold File).Shor tPath
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro cHoldFile, intForReading, False)
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read Line, 28))
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
While Err.Number <> 0 Then
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
Wend
Err.Clear
On Error GoTo 0
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
While Err.Number <> 0 Then
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
Wend
Err.Clear
On Error GoTo 0
End If
Set objOutputFile = objFSO.CreateTextFile(strP
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
While Err.Number <> 0 Then
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
Wend
Err.Clear
On Error GoTo 0
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
ASKER
I get this on the start...
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Delete all files from all computes.vbs
Line: 52
Char: 59
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error
-------------------------- -
OK
-------------------------- -
--------------------------
Windows Script Host
--------------------------
Script: C:\Delete all files from all computes.vbs
Line: 52
Char: 59
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error
--------------------------
OK
--------------------------
Ooops, please remove the "Then" word from the two statements that are:
While Err.Number <> 0 Then
which are on lines 52 and 81.
Regards,
Rob.
While Err.Number <> 0 Then
which are on lines 52 and 81.
Regards,
Rob.
ASKER
Now it gets stuck here
C:\WINDOWS\system32\windev -peers.ini does not exist on DEV-CHEN-PC748
Checking if any other process has a handle on this file.
C:\WINDOWS\system32\windev
Checking if any other process has a handle on this file.
ASKER
Reminder....
Sharath, try this....the only change I've made is to use a maximum retry to delete the file.
Perhaps it is worth finding out what is using ProcHold.txt though....so before you try the below code, run what you have again, then when it gets stuck, open a command prompt on your computer, and run this command in it:
TASKLIST /V | FINDSTR /I "ProcHold.txt"
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull Name, WScript.ScriptName, "") & "ProcHold.txt"
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Set objOutputFile = objFSO.CreateTextFile(strP rocHoldFil e, True)
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold File).Shor tPath
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro cHoldFile, intForReading, False)
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read Line, 28))
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
Perhaps it is worth finding out what is using ProcHold.txt though....so before you try the below code, run what you have again, then when it gets stuck, open a command prompt on your computer, and run this command in it:
TASKLIST /V | FINDSTR /I "ProcHold.txt"
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strProcHoldFile = Replace(WScript.ScriptFull
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Set objOutputFile = objFSO.CreateTextFile(strP
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
ASKER
I get this for the latest script...
C:\Delete all files from all computes.vbs(62, 31) Microsoft VBScript runtime err
or: Permission denied
I tried the first script..The place it gets stuck i put
TASKLIST /V | FINDSTR /I "ProcHold.txt"
It displays nothing..
Can you give me a results file of that success and failures...To know if the script has deleted anything...
C:\Delete all files from all computes.vbs(62, 31) Microsoft VBScript runtime err
or: Permission denied
I tried the first script..The place it gets stuck i put
TASKLIST /V | FINDSTR /I "ProcHold.txt"
It displays nothing..
Can you give me a results file of that success and failures...To know if the script has deleted anything...
ASKER
Here is another
(Failed to delete C:\ProcHold.txt after 10 attempts.)
does not exist on DEV-CHEN-PC1755
Checking if any other process has a handle on this file.
Failed to delete C:\ProcHold.txt after 10 attempts.
C:\Delete all files from all computes.vbs(62, 31) Microsoft VBScript runtime err
or: Permission denied
(Failed to delete C:\ProcHold.txt after 10 attempts.)
does not exist on DEV-CHEN-PC1755
Checking if any other process has a handle on this file.
Failed to delete C:\ProcHold.txt after 10 attempts.
C:\Delete all files from all computes.vbs(62, 31) Microsoft VBScript runtime err
or: Permission denied
Hmmmm, do the DOS commands
TaskList /V
and
findstr /I "computers" c:\*.*
work on your computer? Maybe those command aren't completing?
Rob.
TaskList /V
and
findstr /I "computers" c:\*.*
work on your computer? Maybe those command aren't completing?
Rob.
ASKER
Yes both the command show results...
ASKER
Any help on this Rob....
Please try this. I have changed the output file from "ProcHold.txt" to a randomly generated temporary file that will go into your Temp folder.
'===========
Set objShell = CreateObject("Wscript.Shel l")
If LCase(Right(Wscript.FullNa me, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli st.exe"
strPSListPath = objFSO.getfile(strPSListPa th).ShortP ath
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom putersFile , intForReading, False)
strLog = "Deleting files from remote computers"
Const TemporaryFolder = 2
Set objFolder = objFSO.GetSpecialFolder(Te mporaryFol der)
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil eNamesFile , intForReading, False)
While Not objFileNamesFile.AtEndOfSt ream
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 0, True)
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath & " -accepteula -e \\" & strComputer & " " & strProcessName, 1, True)
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strTempFile = objFSO.GetTempName
strProcHoldFile = objFolder.Path & "\" & strTempFile
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Set objOutputFile = objFSO.CreateTextFile(strP rocHoldFil e, True)
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold File).Shor tPath
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro cHoldFile, intForReading, False)
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read Line, 28))
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH oldFile) = True Then
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del ete_File_R esults.txt ", True)
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel l")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
'===========
Set objShell = CreateObject("Wscript.Shel
If LCase(Right(Wscript.FullNa
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /k cscript """ & strPath & """"
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
strComputersFile = "Computers.txt"
strFileNamesFile = "FilesToDelete.txt"
' Please specify the full path to PSList.exe here
strPSListPath = "n:\utilities\pstools\psli
strPSListPath = objFSO.getfile(strPSListPa
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strCom
strLog = "Deleting files from remote computers"
Const TemporaryFolder = 2
Set objFolder = objFSO.GetSpecialFolder(Te
While Not objInputFile.AtEndOfStream
strUserComputer = objInputFile.ReadLine
If Ping(strUserComputer) = True Then
Set objFileNamesFile = objFSO.OpenTextFile(strFil
While Not objFileNamesFile.AtEndOfSt
'strFileToDelete = "C:\program files\Nokia\nokia pc suite 6\PcSync2.exe"
strFileToDelete = objFileNamesFile.ReadLine
If objFSO.FileExists("\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")) = True Then
strProcessName = Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
If InStr(strProcessName, ".") > 0 Then strProcessName = Left(strProcessName, InStrRev(strProcessName, ".") - 1)
'PSList gives the following return values
' 1 : process does not exist
' 0 : successful - process found
strResponse = objShell.Run(strPSListPath
While strResponse = 0
WScript.Echo strProcessName & " is running."
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & " /T"
objShell.Run strCommand, 0, True
strResponse = objShell.Run(strPSListPath
Wend
' Now look for any process that is not the same name, but may have the file open
boolProcHold = True
While boolProcHold = True
WScript.Echo "Checking if any other process has a handle on this file."
strTempFile = objFSO.GetTempName
strProcHoldFile = objFolder.Path & "\" & strTempFile
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Set objOutputFile = objFSO.CreateTextFile(strP
objOutputFile.Close
Set objOutputFile = Nothing
strProcHoldFile = objFSO.GetFile(strProcHold
strCommand = "cmd /c TASKLIST /S " & strUserComputer & " /V | FINDSTR /I """ & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1) & """ > " & strProcHoldFile
objShell.Run strCommand, 0, True
Set objProcHold = objFSO.OpenTextFile(strPro
If Not objProcHold.AtEndOfStream Then
boolProcHold = True
strHoldingProcess = Trim(Left(objProcHold.Read
WScript.Echo strHoldingProcess & " has a handle on " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
strCommand = "TASKKILL /S " & strUserComputer & " /F /IM " & strHoldingProcess & " /T"
objShell.Run strCommand, 0, True
Else
WScript.Echo "No other process is holding onto " & Mid(strFileToDelete, InStrRev(strFileToDelete, "\") + 1)
boolProcHold = False
End If
objProcHold.Close
Set objProcHold = Nothing
If objFSO.FileExists(strProcH
On Error Resume Next
objFSO.DeleteFile strProcHoldFile, True
intRetry = 0
While Err.Number <> 0 And intRetry < 10
WScript.Sleep 1000
objFSO.DeleteFile strProcHoldFile, True
intRetry = intRetry + 1
Wend
Err.Clear
On Error GoTo 0
If intRetry = 10 Then WScript.Echo "Failed to delete " & strProcHoldFile & " after 10 attempts."
End If
Wend
'WScript.Echo "Attempting to delete " & "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$")
On Error Resume Next
objFSO.DeleteFile "\\" & strUserComputer & "\" & Replace(strFileToDelete, ":", "$"), True
If Err.Number <> 0 Then
WScript.Echo strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
strLog = strLog & VbCrLf & strUserComputer & ": ERROR deleting " & strFileToDelete & " : " & Err.Number & " - " & Err.Description
Err.Clear
On Error GoTo 0
Else
Err.Clear
On Error GoTo 0
WScript.Echo strUserComputer & ": Deleted " & strFileToDelete
strLog = strLog & VbCrLf & strUserComputer & ": Deleted " & strFileToDelete
End If
Else
WScript.Echo strFileToDelete & " does not exist on " & strUserComputer
strLog = strLog & VbCrLf & strFileToDelete & " does not exist on " & strUserComputer
End If
Wend
objFileNamesFile.Close
Set objFileNamesFile = Nothing
Else
WScript.Echo "Could not ping " & strUserComputer
strLog = strLog & VbCrLf & "Could not ping " & strUserComputer
End If
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile("Del
objOutputFile.Write strLog
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo ""
WScript.Echo "Done"
MsgBox "Done"
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shel
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
'===========
Regards,
Rob.
ASKER
Rob as this script searches each file with all the machines it takes a long time to finish and gets stuck some places Is it possible that i a single file ui ahve details as below seperated by a ":" Colon.So that the script can go to the machine and delete the file next to it.
Machine name Filepath
DEV-CHEN-PC2227 F:\autorun.inf
DEV-CHEN-PC2534 C:\WINDOWS\system32\DWRCS. EXE
DEV-CHEN-PC1755 F:\setup.exe
After the script scanned for a long time its stuck here.
C:\WINDOWS\system32\DWRCS. EXE does not exist on DEV-CHEN-PC1567
Checking if any other process has a handle on this file.
Machine name Filepath
DEV-CHEN-PC2227 F:\autorun.inf
DEV-CHEN-PC2534 C:\WINDOWS\system32\DWRCS.
DEV-CHEN-PC1755 F:\setup.exe
After the script scanned for a long time its stuck here.
C:\WINDOWS\system32\DWRCS.
Checking if any other process has a handle on this file.
I don't think we'll try the different format of the text file just yet, we'd probably have similar issues anyway.....
Above each line that reads:
objShell.Run strCommand, 0, True
Please put
WScript.Echo "Running: " & strCommand
so I can see what the command is that gets executed.
Regards,
Rob.
Above each line that reads:
objShell.Run strCommand, 0, True
Please put
WScript.Echo "Running: " & strCommand
so I can see what the command is that gets executed.
Regards,
Rob.
ASKER
I get this...
C:\WINDOWS\system32\DWRCS. EXE does not exist on DEV-CHEN-PC1567
Checking if any other process has a handle on this file.
Running: cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE" > C:\DOC
UME~1\ADMINI~1.DEV\LOCALS~ 1\Temp\rad 3E7E3.tmp
C:\WINDOWS\system32\DWRCS.
Checking if any other process has a handle on this file.
Running: cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE" > C:\DOC
UME~1\ADMINI~1.DEV\LOCALS~
OK, so if you run
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
and if that works, then run
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE" > C:\SomeTempFile.txt
does that work?
Regards,
Rob.
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
and if that works, then run
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE" > C:\SomeTempFile.txt
does that work?
Regards,
Rob.
ASKER
I get this...
C:\>cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
ERROR: Logon failure: unknown user name or bad password.
C:\>cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
ERROR: Logon failure: unknown user name or bad password.
Sharath, I would expect that all of these "Logon Failures" or "Access Denied" errors that you are getting seem to be the result of either
a) Simple File Sharing is enabled
- Disable via Windows Explorer --> Tools --> Folder Options --> View tab --> untick Use Simple File Sharing
or b) DCOM Permission Issues or WMI Corruption
Try running the WMI diagnostic tool:
http://www.microsoft.com/downloads/details.aspx?familyid=D7BA3CD6-18D1-4D05-B11E-4C64192AE97D&displaylang=en
You can also try a few other steps, which the diagnostic tool should pick up anyway....
On the remote machine, please check that DCOM is enabled, and make sure it has the correct permissions to allow COM objects to run. Click Start --> Settings --> Control Panel --> Administrative Tools --> Component Services
Then expand Component Services --> Computers --> My Computer
Right click My Computer, go to Properties. On the Default Properties tab, check the Enable Distributed COM on this computer box.
Then on the COM Security tab, click Edit Default... under Launch and Activation Permissions and make sure the Local Administrators group has Full Access.
Then make sure that your domain account is in the Local Administrators group in Computer Management. Restart the system and try again.
So, essentially, make sure all this is healthy on the target system, then run
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
again.
Regards,
Rob.
a) Simple File Sharing is enabled
- Disable via Windows Explorer --> Tools --> Folder Options --> View tab --> untick Use Simple File Sharing
or b) DCOM Permission Issues or WMI Corruption
Try running the WMI diagnostic tool:
http://www.microsoft.com/downloads/details.aspx?familyid=D7BA3CD6-18D1-4D05-B11E-4C64192AE97D&displaylang=en
You can also try a few other steps, which the diagnostic tool should pick up anyway....
On the remote machine, please check that DCOM is enabled, and make sure it has the correct permissions to allow COM objects to run. Click Start --> Settings --> Control Panel --> Administrative Tools --> Component Services
Then expand Component Services --> Computers --> My Computer
Right click My Computer, go to Properties. On the Default Properties tab, check the Enable Distributed COM on this computer box.
Then on the COM Security tab, click Edit Default... under Launch and Activation Permissions and make sure the Local Administrators group has Full Access.
Then make sure that your domain account is in the Local Administrators group in Computer Management. Restart the system and try again.
So, essentially, make sure all this is healthy on the target system, then run
cmd /c TASKLIST /S DEV-CHEN-PC1567 /V | FINDSTR /I "DWRCS.EXE"
again.
Regards,
Rob.
ASKER
Rob any machines that have such problems can it skip them and continue...
I am checking the Wmi
I am checking the Wmi
OK, that means we'll have to read the output of the TASKLIST command, so I'll work on that...
Regards,
Rob.
Regards,
Rob.
ASKER
Rob how can i find the issues in the logs files that are created
WMI diagnostic tool:
I can send the zip file if you can give your email id if possible...
WMI diagnostic tool:
I can send the zip file if you can give your email id if possible...
ASKER
Reminder..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob this goes on without any error.
I shall close this Q and raise a new one.
Can you help changing the way the script works.
I have the Machine name and filetodelete next to each other.
Any way that it deletes the file in the exact machine
Say i have 200 computers and 300 files.At present this script takes each file and scans every computers for just 1 file to delete in 1 computer.
I shall close this Q and raise a new one.
Can you help changing the way the script works.
I have the Machine name and filetodelete next to each other.
Any way that it deletes the file in the exact machine
Say i have 200 computers and 300 files.At present this script takes each file and scans every computers for just 1 file to delete in 1 computer.
Yeah, that should be fine....if you have specific files to delete for specific computers, then that makes sense anyway.
Raise another question, and I'll change the way it takes the input, and get rid of the need for two input files.
Regards,
Rob.
Raise another question, and I'll change the way it takes the input, and get rid of the need for two input files.
Regards,
Rob.
ASKER
Rob i have posted a new Q...here
https://www.experts-exchange.com/questions/22908293/Delete-files-from-machines.html
https://www.experts-exchange.com/questions/22908293/Delete-files-from-machines.html
ASKER
DEV-CHEN-PC1703: ERROR deleting D:\program files\stickypad\stickypad.
Permission denied
C:\program files\quicktime alternative\qttask.exe does not exist on DEV-CHEN-PC1
703
D:\program files\stickypad\stickypad.
DEV-CHEN-PC378: ERROR deleting C:\program files\quicktime alternative\qttask.exe
: 70 - Permission denied