/build/static/layout/Breadcrumb_cap_w.png

urgent!!

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

Answers (6)

Posted by: anonymous_9363 13 years ago
Red Belt
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.
Posted by: ritutiw 13 years ago
Senior Yellow Belt
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!!
Posted by: anonymous_9363 13 years ago
Red Belt
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.
Posted by: pjgeutjens 13 years ago
Red Belt
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
Posted by: anonymous_9363 13 years ago
Red Belt
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.
Posted by: ritutiw 13 years ago
Senior Yellow Belt
0
oh gr8 idea.
[:)]thanx
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ