→ 🚀What's New? Explore Lansweeper's Fall 2024 Updates! Fall Launch Blog !
‎07-08-2015 02:54 PM
Option Explicit
Const ForWriting = 2
Const ForAppending = 8
Dim objFSO 'File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTS 'Text Stream Object
Dim objWS 'WScript object
Dim Drive 'Parameter: drive to search in
Dim Filetype 'Parameter: file type to search for
Dim objFile 'file found
Dim query 'WMI query string
Dim searchstring 'files to search for
Dim path 'Parameter: path of files to be searched
Dim target 'Parameter: file location of output file
Dim targetfolder 'Folder of the output file
Dim arg 'script arguments
Dim drivesinfo 'search info string drives
Dim typesinfo 'search info string filetypes
Dim info 'search info text
Dim i 'counter
Dim starttime 'start time for duration
'Read script arguments
if wscript.arguments.Named.count > 0 then
if WScript.Arguments.Named("drive") <> "" Then
Drive = WScript.Arguments.Named("drive")
End If
if WScript.Arguments.Named("type") <> "" Then
Filetype = WScript.Arguments.Named("type")
End If
if WScript.Arguments.Named("path") <> "" Then
path = WScript.Arguments.Named("path")
If Left(path,1) <> "\" Then path = "\" & path
End If
if WScript.Arguments.Named("target") <> "" Then
target = WScript.Arguments.Named("target")
End If
End if
'Build search query
If Len(Drive) > 0 Then
searchstring = Drive & ":"
Else
searchstring = "c:"
End if
If Len(path) > 0 Then
searchstring = searchstring & path
if Right(searchstring,1) <> "\" then searchstring = searchstring & "\"
Else
searchstring = searchstring & "\"
End if
If Len(Filetype) > 0 Then
searchstring = searchstring & "*." & Filetype
Else
searchstring = searchstring & "*.*"
End if
'Define scan result target location and open file
If Not Len(target)>0 Then target = "C:\temp\LSfilesearch.txt"
targetfolder = Mid(target,1,InStrRev(target,"\"))
If Not objFSO.FolderExists(targetfolder) Then objFSO.CreateFolder(targetfolder)
Set objTS = objFSO.OpenTextFile(target, ForWriting, True)
'write file search parameters into result file
starttime = Now()
info = "Starting file search on drive "
If Len(drive)>0 Then info = info & drive & ":" else info = info & "c:"
If Len(Filetype)>0 Then info = info & " for file type " & Filetype
If Len(path)>0 then info = info & " under path """ & path & """"
objTS.WriteLine(info & vbCrLf & "---")
objTS.Close()
'Execute search
query = """%comspec%"" /e:4096 /s /c dir /s "
if LCase(WScript.Arguments.Named("bare")) = "true" Then query = query & "/b"
query = query & "/o """ & searchstring & """ >> " & target
Set objWS = CreateObject("Wscript.Shell")
objWS.Run query, 0, True
Set objTS = objFSO.OpenTextFile(target, ForAppending, False)
objTS.WriteLine("---" & vbCrLf & "Search completed in " & _
Datediff("s",starttime,now()) & " seconds")
objTS.Close()
WScript.Quit 0
‎07-28-2015 07:27 PM
‎08-01-2015 01:48 PM
leblanc.daniel.4@hydro.qc.ca wrote:
Where do we put this file and how to apply on Lansweeper server??
Dan
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now