Hi all,
i am a beginner in Vbs.Actually i am writing a script to delete folders and subfolders from ramote machine.in this i am using mapping of the given folder to local machine.My script works for mapping and deletion but it is not able to remove mapped drive.Can you look into the script plz

' Sets Up Log File

Const OPEN_FILE_FOR_WRITE = 2
Const OPEN_FILE_FOR_APPEND = 8



Set objFileSystem = CreateObject("Scripting.FileSystemObject")

strOutputLog = "C:\Temp\FolderCheck.log"

Set LogFile = objFileSystem.OpenTextFile(strOutputLog,OPEN_FILE_FOR_APPEND,true)

'LogFile.Writeline (Now & " Username : " & strWinntUserName)
'LogFile.Writeline (Now & " Computer Name : " & strComputerName)
'LogFile.Writeline ""

arrComputers = Split("10.102.16.55", ";")

For Each strComputer In arrComputers
if strComputer <> "" Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")

WshNetwork.MapNetworkDrive "P:", "\\" & StrComputer & "\C$\ Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5"

Set objFolder = objFso.GetFolder("P:\")
killFiles(objFolder) 'Delete files
getSubfolders(objFolder) 'Delete files in subfolders
Set objFolder = Nothing
Msgbox strComputer &"fle deleted"
WshNetwork.RemoveNetworkDrive "P:"
else
Msgbox strComputer & "has not been processed."
End If
Next

Sub killFiles (ByRef objFolder) 'Delete all files in folder
Set colFiles = objFolder.Files

On Error Resume Next
For Each objFile In colFiles
objFile.Delete
Next
On Error Goto 0
End Sub


Sub getSubFolders(ByRef objParentFolder) 'If subfolders exist, process files
' in each folder
Set colSubfolders = objParentFolder.SubFolders
For Each objSubfolder In colSubfolders
killFiles(objSubfolder)
If objSubfolder.SubFolders.Count > 0 Then
getSubFolders(objSubFolder)
End If
objSubfolder.Delete
Next
End Sub
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
arrComputers = Split("10.102.16.55", ";")
You are attempting to split a string using a character which doesn't appear in the string. Presumably you've removed another IP address from the string and that the list is actually delimited using semi-colon? WshNetwork.MapNetworkDrive "P:", "\\" & StrComputer & "\C$\ Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5"I think the fact that the drive is mapped to the actual folder, rather than the share, keeps a handle on that folder open, meaning that it cannot be deleted. I think you probably want to map only as far as the hidden share (C$) and then add the folder information to the file deletion code.
Answered 06/30/2010 by: VBScab
Red Belt

Please log in to comment
0
srry there i m using computer name
arrComputers = Split("vmxpprescev01", ";")
but it is not working..and the drive is mapping to the share folder only
any suggestion!!
Answered 06/30/2010 by: ritutiw
Senior Yellow Belt

Please log in to comment
0
the drive is mapping to the share folder only Would you post the revised code, then? Don't forget to use the CODE tag when posting code and other lengthy text.
Answered 06/30/2010 by: VBScab
Red Belt

Please log in to comment
0
drive is mapping to the share folder only
WshNetwork.MapNetworkDrive "P:", "\\" & StrComputer & "\C$\ Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5"

Dunno if you did a straight copy-paste of your script, but is that a space I detect between C$\ and Documents?

PJ
Answered 06/30/2010 by: pjgeutjens
Red Belt

Please log in to comment
0
We're a couple of clods, aren't we, Pieter?

@ritutiw, why bother mapping the drive? Just refer to the remote machine as a UNC. That is, pass KillFiles the entire path:Set objFolder = objFso.GetFolder("\\" & StrComputer & "\C$\Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5" )
killFiles(objFolder)
You should also add some error-trapping by testing for the folder's existence before attempting to delete it and also after deletion, the latter to ensure that the deletion happened.

Oh and BTW, you want the 'objFolder' variable in 'Sub KillFiles' to be referred to by value (ByVal) rather than by reference (ByRef). Check out MSDN for a good explanation of the difference.
Answered 06/30/2010 by: VBScab
Red Belt

Please log in to comment
0
oh gr8 idea.
[:)]thanx
Answered 06/30/2010 by: ritutiw
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity