Delete folder on multiple usb drives VBS - vbscript

I am looking to delete folder on multiple usb driver at the same time.
sDeleteFolder = "\Test"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set dUSBKeys = ScanForUSBKeys()
For Each oUSBKey in dUSBKeys.Keys
If Left(oUSBKey, 1) = "\" Then
sKey = oUSBKey
Else
sKey = oUSBKey & "\"
End If
oFS.DeleteFolder sdeleteFolder, sKey
Next
Set dUSBKeys = Nothing
Set oFS = Nothing
MsgBox "Done Del all the folder from USB Drivs", vbOKOnly+VBINformation+VBSystemModal, "DONE"
Function ScanForUSBKeys()
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set dTemp = CreateObject("Scripting.Dictionary")
Set cDisks = oWMI.ExecQuery("Select InterfaceType,MediaType,PNPDeviceID,DeviceID,Size from Win32_DiskDrive")
For Each oDisk in cDisks
If InStr(LCase(oDisk.InterfaceType),"usb") > 0 AND InStr(LCase(oDisk.MediaType),"removable") > 0 _
AND InStr(LCase(oDisk.PNPDeviceID),"blackberry") = 0 AND InStr(LCase(oDisk.PNPDeviceID),"ipod") = 0 _
AND NOT oDisk.PNPDeviceID = "" Then
Set cDrivePartitions = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & _
oDisk.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" )
For Each oDrivePartition in cDrivePartitions
Set cDriveLetters = oWMI.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & _
oDrivePartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each oDriveLetter in cDriveLetters
dTemp.Add oDriveLetter.DeviceID, 1
Next
Set cDriveLetters = Nothing
Next
Set cDrivePartitions = Nothing
End If
Next
Set cDisks = Nothing
Set ScanForUSBKeys = dTemp
Set dTemp = Nothing
Set oWMI = Nothing
End Function
I keep getting a error :
Type mismatch: 'oFs.DeleteFolder'
Line 12 Char 5

Study the docs for .DeleteFolder
Make sure you pass the full path (not just "\test") and the appropriate boolean (not a string like oUSBKey) when you call the Sub
Use .BuildPath to build that full path
Use the good features of VBScript. E.g.: Option Explicit, declare sPath as Const
Don't use Set x = Nothing in vain

Try this code
sDeleteFolder = "\Test"
For Each oUSBKey in dUSBKeys.Keys
sKey = oUSBKey & sDeleteFolder
oFS.DeleteFolder sKey
Next

Related

Get disks information and output to one line

I am trying to read the information on the storage drives and would like to output the results as (on 1 line):
1/2 - Samsung Evo - 500GB - 4 partitions - C :, D :, E :, F:
2/2 - USB Transcend - 16GB - 2 partitions - G :, H:
On Error Resume Next
' Create a FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
' Provide file path
Dim result, strComputer, outFile, PropertyArr, ArrayItem
outFile = "C:\Users\MISS\Desktop\ok.txt"
' Sets computer name to the current computer name
strComputer = "."
' Setting up file to write
Set objFile = FSO.CreateTextFile(outFile, True)
' Connect to the WMI Service
Set CIMV2 = GetObject("winmgmts:" & "\\" & strComputer & "\root\CIMV2")
If Err Then
WScript.StdOut.WriteLine "Unable to access WMI Service."
WScript.Quit 32
End If
' Fetch all details from Win32_computersystem
Set Win32_DiskDrive = CIMV2.ExecQuery("Select * from Win32_DiskDrive")
PropertyArr = Array("Model","MediaType")
For Each item_PropertyArr In PropertyArr
ArrayItem = item_PropertyArr
Next
For Each item In Win32_DiskDrive
result = item.ArrayItem
WScript.Echo "Result: " & result
Next
Set FSO = Nothing
It is empty result.
To get the string output in the desired format, I would suggest using a template string and use Replace() to fill in the details.
Because you want the driveletters that are associated with each partition aswell, you need to do more than just query the Win32_DiskDrive, because that query does not return driveletters. See here
The below code should do what you want:
Option Explicit
Const ForAppending = 8
Dim objFso, objFile, objWMIService, colDiskDrives, objDiskDrive
Dim colPartitions, objDiskPartition, colLogicalDisks, objDriveLetters, objLogicalDisk
Dim outFile, strFormat, strResult, numCurrentDrive, strMediaType, strID, strQuery, strComputer
On Error Resume Next
' set up file to write
outFile = "C:\Users\MISS\Desktop\ok.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(outFile) Then objFso.DeleteFile outFile, True
Set objFile = objFso.OpenTextFile(outFile, ForAppending, True)
strComputer = "."
Set objWMIService = GetObject( "winmgmts:{ impersonationLevel=Impersonate }!//" & strComputer )
Set colDiskDrives = objWMIService.ExecQuery( "Select * FROM Win32_DiskDrive" )
'set up a string as template for the output
strFormat = "{0}/{1} - {2} - {3} - {4} partition(s)"
'create a variable for the current disk count
numCurrentDrive = 1
For Each objDiskDrive In colDiskDrives
'start building the string to output
strMediaType = objDiskDrive.MediaType
If IsNull(strMediaType) Or Len(strMediaType) = 0 Then strMediaType = "Unknown"
strResult = Replace(strFormat, "{0}", numCurrentDrive)
strResult = Replace(strResult, "{1}", colDiskDrives.Count)
strResult = Replace(strResult, "{2}", objDiskDrive.Model)
strResult = Replace(strResult, "{3}", strMediaType)
strResult = Replace(strResult, "{4}", objDiskDrive.Partitions)
'increase the current drive counter
numCurrentDrive = numCurrentDrive + 1
'create an arraylist to capture the drive letters
Set objDriveLetters = CreateObject("System.Collections.ArrayList")
'escape the backslashes in objDiskDrive.DeviceID for the query
strID = Replace( objDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare )
strQuery = "Associators Of {Win32_DiskDrive.DeviceID=""" & strID & """} Where AssocClass = Win32_DiskDriveToDiskPartition"
Set colPartitions = objWMIService.ExecQuery(strQuery)
For Each objDiskPartition In colPartitions
'get the drive letter for each partition
strQuery = "Associators Of {Win32_DiskPartition.DeviceID=""" & objDiskPartition.DeviceID & """} Where AssocClass = Win32_LogicalDiskToPartition"
Set colLogicalDisks = objWMIService.ExecQuery(strQuery)
For Each objLogicalDisk In colLogicalDisks
objDriveLetters.Add objLogicalDisk.DeviceID
'objDriveLetters.Add objLogicalDisk.VolumeName
Next
Set colLogicalDisks = Nothing
Next
'add the driveletters to the output string
strResult = strResult & " - " & Join(objDriveLetters.ToArray(), ", ")
Set objDriveLetters = Nothing
Set colPartitions = Nothing
'output on screen
WScript.Echo strResult
'output to file
objFile.WriteLine strResult
Next
'close the file
objFile.Close
Set objFile = Nothing
Set colDiskDrives = Nothing
Set objWMIService = Nothing
Update
As per your comments, you would like to not use .NET (the ArrayList) in the code. This can be done of course, but with a little bit more effort:
Option Explicit
Const ForAppending = 8
Dim objFso, objFile, objWMIService, colDiskDrives, objDiskDrive
Dim colPartitions, objDiskPartition, colLogicalDisks, objLogicalDisk
Dim outFile, strFormat, strResult, strMediaType, strID, strQuery, strComputer
Dim arrDriveLetters, numCurrentDrive, numDriveLetters
On Error Resume Next
' set up file to write
outFile = "C:\Users\MISS\Desktop\ok.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(outFile) Then objFso.DeleteFile outFile, True
Set objFile = objFso.OpenTextFile(outFile, ForAppending, True)
strComputer = "."
Set objWMIService = GetObject( "winmgmts:{ impersonationLevel=Impersonate }!//" & strComputer )
Set colDiskDrives = objWMIService.ExecQuery( "Select * FROM Win32_DiskDrive" )
'set up a string as template for the output
strFormat = "{0}/{1} - {2} - {3} - {4} partition(s)"
'create a variable for the current disk count
numCurrentDrive = 1
For Each objDiskDrive In colDiskDrives
'start building the string to output
strMediaType = objDiskDrive.MediaType
If IsNull(strMediaType) Or Len(strMediaType) = 0 Then strMediaType = "Unknown"
strResult = Replace(strFormat, "{0}", numCurrentDrive)
strResult = Replace(strResult, "{1}", colDiskDrives.Count)
strResult = Replace(strResult, "{2}", objDiskDrive.Model)
strResult = Replace(strResult, "{3}", strMediaType)
strResult = Replace(strResult, "{4}", objDiskDrive.Partitions)
'increase the current drive counter
numCurrentDrive = numCurrentDrive + 1
'reset the dynamic array to capture the drive letters
numDriveLetters = 0
ReDim arrDriveLetters(numDriveLetters)
'escape the backslashes in objDiskDrive.DeviceID for the query
strID = Replace( objDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare )
strQuery = "Associators Of {Win32_DiskDrive.DeviceID=""" & strID & """} Where AssocClass = Win32_DiskDriveToDiskPartition"
Set colPartitions = objWMIService.ExecQuery(strQuery)
For Each objDiskPartition In colPartitions
'get the drive letter for each partition
strQuery = "Associators Of {Win32_DiskPartition.DeviceID=""" & objDiskPartition.DeviceID & """} Where AssocClass = Win32_LogicalDiskToPartition"
Set colLogicalDisks = objWMIService.ExecQuery(strQuery)
For Each objLogicalDisk In colLogicalDisks
ReDim Preserve arrDriveLetters(numDriveLetters)
arrDriveLetters(numDriveLetters) = objLogicalDisk.DeviceID
numDriveLetters = numDriveLetters + 1
Next
Set colLogicalDisks = Nothing
Next
'add the driveletters to the output string
strResult = strResult & " - " & Join(arrDriveLetters, ", ")
Erase arrDriveLetters
Set colPartitions = Nothing
'output on screen
WScript.Echo strResult
'output to file
objFile.WriteLine strResult
Next
'close the file
objFile.Close
Set objFile = Nothing
Set colDiskDrives = Nothing
Set objWMIService = Nothing
The output will be something like
1/4 - Samsung SSD 750 EVO 250GB ATA Device - Fixed hard disk media - 1 partition(s) - C:
2/4 - ST3500418AS ATA Device - Fixed hard disk media - 1 partition(s) - E:
3/4 - WDC WD7501AALS-00J7B0 ATA Device - Fixed hard disk media - 1 partition(s) - D:
4/4 - Generic Ultra HS-SD/MMC USB Device - Unknown - 0 partition(s)
Hope that helps
P.S. Best run using CScript instead of WScript, to avoid having popup messages with one line at a time

Receiving error code 424 in VBA when attempting to use CopyHere method with built in Windows Zip

I am receiving the object required error on the following line, although fl4 is a defined variant/object/file:
oFold.CopyHere (fl4)
Any thoughts would be appreciated.
Below is an applicable excerpt of code. I have excluded the recursive loop and directory sub folder iteration:
srcpth = rs1.Fields("Src_File_Path").Value
destpth = rs1.Fields("Zip_File_Path").Value
var = 0
Set FS2 = New FileSystemObject
Set FS2 = CreateObject("Scripting.FileSystemObject")
Set fl1 = FS2.GetFolder(srcpth)
For Each fl2 In FS2.GetFolder(srcpth).SubFolders
var = 2
ZipFile = Application.CurrentProject.Path & "\tmp\" & fl2.Name & ".zip"
Set FS3 = CreateObject("Scripting.FileSystemObject")
FS3.CreateTextFile(ZipFile, True).Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)
Set FS3 = Nothing
Set FS4 = New FileSystemObject
Set FS4 = CreateObject("Scripting.FileSystemObject")
Set fl3 = FS4.GetFolder(fl2)
For Each fl4 In FS4.GetFolder(fl2).Files
var = 2
GoTo Zipxchg
zipxchg_2:
Next
Next
Set FS1 = Nothing
Set oFld = Nothing
Set oApp = Nothing
Set oShl = Nothing
Exit Sub
Zipxchg:
If var = 2 Then
ZipFile = Application.CurrentProject.Path & "\tmp\" & fl2.Name & ".zip"
Set oApp = CreateObject("Shell.Application")
Set oFld = oApp.NameSpace(CVar(ZipFile))
Set FilestoZip = objShell.File(fl4)
i = oFld.Items.Count
oFold.CopyHere (fl4)
Set oShl = CreateObject("WScript.Shell")
GoTo zipxchg_2
End Sub
remove the brackets .... use oFold.CopyHere fl4 .... brackets cause a value to be returned, but there is no variable (object) to receive it

Return line number or subsequent text of a text file string search

I have a several text files that have thousands of lines each with this being an example of a typical line:
PCI\VEN_10EC&DEV_8168&REV_09 Realtek\5x64\FORCED\PCIe_5.810.1218.2012\ Netrtle.inf Realtek 1 12/18/2012,5.810.1218.2012 Realtek PCIe GBE Family Controller
The script I'm working on does a string search for that first segment of text:
PCI\VEN_10EC&DEV_8168&REV_09
My script narrows down which files have this string, but what I really need is for it then to return the next string on that same line:
Realtek\5x64\FORCED\PCIe_5.810.1218.2012\
Once I have this string I can continue on with the rest of the script which is just extracting the Realtek folder from a 7zip.
I've seen this has been done with other languages on Stack but I can't find anything for VBS. I could probably find an answer if I knew how to phrase the task better. I'd really appreciate some advise on grabbing that second string.
For background, this is the script I'm working on. It looks through all the text files in C:\scripts\ for a string returned by a WMI query for CompatibleID of device drivers with code 28 (no driver installed):
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objNet = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PnPEntity " _
& "WHERE ConfigManagerErrorCode = 28")
For Each objItem in colItems
Dim arrCompatibleIDs
aarCompatibleIDs = objItem.CompatibleID
for each objComp in aarCompatibleIDs
Dim FirstID
FirstID = objComp
Exit For
Next
Next
strSearchFor = firstID
objStartFolder = "C:\scripts"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
strFile = "C:\scripts\" & objFile.Name
set objFile = objFSO.getFile(strFile)
if objFile.size > 0 then
If InStr(objFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
msgbox(objfile.name)
Else
WScript.Sleep (100)
End If
End If
Next
If you need to search for a fixed needle and a variable thread in a haystack, you can use some InStr()s or a RegExp. To get you started:
Dim sHaystack : sHaystack = Join(Array( _
"hay hay" _
, "fixed_needle variable_thread hay" _
, "hay hay" _
), vbCrLf)
Dim sNeedle : sNeedle = "fixed_needle" & " "
Dim nPosN : nPosN = Instr(sHaystack, sNeedle)
If 0 < nPosN Then
nPosN = nPosN + Len(sNeedle)
Dim nPosT : nPosT = Instr(nPosN, sHaystack, " ")
If 0 < nPosN Then
WScript.Echo "Instr()", qq(Mid(sHaystack, nPosN, nPosT - nPosN))
Else
WScript.Echo "no thread"
End If
Else
WScript.Echo "no needle"
End If
Dim reNT : Set reNT = New RegExp
reNT.Pattern = sNeedle & "(\S+) "
Dim oMTS : Set oMTS = reNT.Execute(sHayStack)
If 1 = oMTS.Count Then
WScript.Echo "RegExp ", qq(oMTS(0).SubMatches(0))
Else
WScript.Echo "no match"
End If
output:
Instr() "variable_thread"
RegExp "variable_thread"
If you change the haystack to
Dim sHaystack : sHaystack = Join(Array( _
"hay hay" _
, "fixed_needle no_variable_thread_hay" _
, "hay hay" _
), vbCrLf)
output:
Instr() "no_variable_thread_hay
hay"
no match
you see that there is more work needed to make the Instr() approach bulletproof.
Since your input file seems to be tab-separated, you could do something like this:
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 28"
For Each entity In wmi.ExecQuery(qry)
For Each cid In entity.CompatibleID
firstID = cid
Exit For
Next
Next
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In objFSO.GetFolder(objStartFolder).Files
If f.Size > 0 Then
For line In Split(f.OpenAsTextStream.ReadAll, vbNewLine)
arr = Split(line, vbTab)
If arr(0) = firstID Then MsgBox arr(1)
Next
End If
Next
On a more general note, you shouldn't do stuff like this:
Set colFiles = objFolder.Files
For Each objFile in colFiles
strFile = "C:\scripts\" & objFile.Name
set objFile = objFSO.getFile(strFile)
if objFile.size > 0 then
If InStr(objFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
...
The Files collection already contains File objects, so it's utterly pointless to build a pathname from the object's properties (which BTW include a Path property that gives you the full path) only to obtain the exact same object you already have. Plus, file objects have a method OpenAsTextStream, so you can directly open them as text files without taking a detour like objFSO.OpenTextFile(f.Path).

Find all photographs taken on a certain date

If have the following VBScript for recursively finding all the files in a set of folders. I simply found this on the web somewhere and can't take credit for it.
fileExtension = ".jpg"
folderPath = "C:\Pictures"
computerName = "."
arrFIL = Array()
If Right(folderPath,1) = "\" Then folderPath = Left(folderPath,Len(folderPath)-1)
Set wmiObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\cimv2")
Set folderObject = wmiObject.Get("Win32_Directory='" & folderPath & "'")
EnumFolders folderObject, wmiObject, arrFIL
strFIL = UBound(arrFIL) + 1 & " files found with extension '" & fileExtension & "':" & vbCrLf & vbCrLf
For intFIL = 0 To UBound(arrFIL)
Set objFile = objFSO.GetFile(arrFIL(intFIL))
strFIL = strFIL & arrFIL(intFIL) & vbCrLf
Next
WScript.Echo strFIL
Sub EnumFolders(folderObject, wmiObject, arrFIL)
On Error Resume Next
Dim objSD1
Dim objSD2
Dim objFI1
Dim objFI2
Set objSD1 = wmiObject.ExecQuery("Associators of {Win32_Directory.Name='" & fold erObject.Name & "'} Where AssocClass=Win32_SubDirectory ResultRole=PartComponent")
For Each objSD2 in objSD1
EnumFolders objSD2, wmiObject, arrFIL
Next
On Error Goto 0
Set objFI1 = wmiObject.ExecQuery("Associators of {Win32_Directory.Name='" & folderObject.Name & "'} Where ResultClass=CIM_DataFile")
For Each objFI2 in objFI1
If Right(objFI2.Name,Len(fileExtension)) = fileExtension Then
intFIL = UBound(arrFIL) + 1
ReDim Preserve arrFIL(intFIL)
arrFIL(intFIL) = objFI2.Name
End If
Next
End Sub
What I need to do is run this against a bunch of folders, within C:\Pictures, and have it return all files where the Date Taken property of the photo is the 23rd of the month. Is this possible? How would I achieve this?
Thanks
I'd use the Shell.Application object instead of WMI:
Const Name = 0
Const DateTaken = 12
folderPath = "C:\Pictures"
Set re = New RegExp
re.Pattern = "[^0-9:./ ]"
re.Global = True
Traverse CreateObject("Shell.Application").Namespace(folderPath)
Sub Traverse(fldr)
For Each obj In fldr.Items
If obj.IsFolder Then
Traverse obj.GetFolder
ElseIf LCase(obj.Type) = "jpeg image" Then
If Day(re.Replace(fldr.GetDetailsOf(obj, DateTaken), "")) = 23 Then
WScript.Echo fldr.GetDetailsOf(obj, Name)
End If
End If
Next
End Sub

VBScript: way to check why the script stopped?

I have this VBScript which runs however, while it is processing, it will randomly stop and require a user to hit the spacebar for it to display the rest of its ongoing output.
How do I figure out why this is happening?
Here is a copy of the script:
'On Error Resume Next
Dim arrFolders()
intSize = 0
Function StampNow()
Dim Hr, Mn, Yr, Mon, Dy, Date1
Date1=Now()
Hr=DatePart("h",Date1)
Mn=DatePart("n",Date1)
Yr = DatePart("yyyy",Date1)
Mon = DatePart("m",Date1)
Dy = DatePart("d",Date1)
StampNow = Yr & "-" & Mon & "-" & Dy
end function
'Output log info.
Function OutputToLog (strToAdd)
Dim strDirectory,strFile,strText, objFile,objFolder,objTextFile,objFSO
strDirectory = "c:\log"
strFile = "\dpadmin_copy2run-"& StampNow & ".bat"
'strText = "dpadmin_copy2"
strText = strToAdd
' Create the File System Object.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists.
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
'WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
'Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
' Writes strText every time you run this VBScript.
objTextFile.WriteLine(strText)
objTextFile.Close
End Function
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strFolderName = "D:\1\production\Openjobs"
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
dim diffindates
'Init vars for regex.
Dim retVal, retVal2
Dim Lastprop
Dim objRegExpr 'regex variable
Set objRegExpr = New regexp
Set objRegExprX31 = New regexp
objRegExpr.Pattern = "[0-9][0-9][0-9][0-9][0-9][0-9][A-Z][A-Z][A-Z]"
objRegExprX31.Pattern = "[0-9][0-9][0-9][0-9][0-9][0-9]X31"
objRegExpr.Global = True
objRegExprX31.Global = True
objRegExpr.IgnoreCase = True
objRegExprX31.IgnoreCase = True
'Variables for getting last accessed property.
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
'Current time vars.
Dim currenttime
currenttime = Now()
ParentFolder = "D:\1\Production\Openjobs\ClosedJobs"
For Each objFolder in colSubfolders
intSize = intSize + 1
retVal = objRegExpr.Test(objFolder.Name)
retVal2 = objRegExprX31.Test(objFolder.Name)
if (retVal OR retVal2 ) then
'set filename to array
strFolderName = objFolder.Name
'Get last modified date.
Set f = fs.GetFolder(objFolder.Name)
Lastprop = f.DateLastModified
'MsgBox(Lastprop)
if ( DateDiff("m", f.DateLastModified, Now()) > 4) then
diffindates = DateDiff("m", f.DateLastModified, Now())
Set objShell = CreateObject("Shell.Application")
Set objCopyFolder = objShell.NameSpace(ParentFolder)
OutputToLog("rem " & f.DateLastModified & ":" & objFolder.Name )
outputtolog("move /Y """ & objFolder.Name & """ " & ParentFolder)
wscript.echo(diffindates & ":" & objFolder.Name & vbCr)
end if
end if
Next
Update
It stops at the line:
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
with the error Microsoft VBScript runtime error: Permission denied
I'm a little confusd by this. The logfile was only 356kb
I was able to run your script several times without it pausing for input. Run your script with the //X flag to start it in the debugger:
>cscript //nologo //X dpadmin_copy2.vbs"
You should be able to then step through the code.
You can also start putting in wscript.echo trace statements everywhere and see if you can narrow down what it's waiting on.
One thing that's gotten me in the past; If your command console is in QuickEdit mode and you accidentally click anywhere in the console window, the console will hang while it waits for you to press a key.
Well the first step is to remove any global On Error Resume Next statements. Better feedback would come if we could see the script.
You usually get an Permission denied when trying to write to a text file when the text file already has an open handle from some other process or because you have previously opened a handle earlier in you code which you have not closed. I haven't tried this but I don't know why this wouldn't work, you can look at using Handle from Sysinternals (Microsoft) to tell you what process has the open handle for the file. Please see here for a further reference of how to use Handle: http://www.orcsweb.com/blog/post/Closing-open-file-handles.aspx You could also write a second script which runs in a loop to monitor the main script. The second script can verify the first script by doing a WMI Process query which returns only processes that match a defined command line. The second script could then restart the main it stops, alert you, log a file, launch a handle search, etc.

Resources