OK this was working and now I can't seem to get it to work from any remote machine or locally. I am trying to delete a network share and I have tried a couple different techniques. I must not have something correct. here are the techniques I am using:
and
Code:
DeleteUsrFolder(DeleteME)
WScript.Echo "Done"
Sub DeleteUsrFolder(UserString)
strComputer = "machine-name"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = '" & UserString & "'")
For Each objShare in colShares
WScript.Echo objShare.Name
objShare.Delete
Next
end Sub
Code:
DeleteUsrFolder(DeleteME)
WScript.Echo "Done"
sub DeleteUsrFolder(UserString)
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oDelFolder
Dim oFileCollection
Dim oFile
Dim oFolderCollection
strComputer = "machine-name"
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "\\" & strComputer & "\" & UserString
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFolderCollection = oFolder.SubFolders
set oFileCollection = oFolder.Files
For each oFile in oFileCollection
oFile.Delete(True)
Next
For each oDelFolder in oFolderCollection
oDelFolder.Delete(True)
Next
'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
end Sub