Click to See Complete Forum and Search --> : Problem with using SearchTreeForFile to find files
Innofin
Nov 2nd, 2001, 08:05 AM
Hi,
I am trying to find a file on a machine using
SearchTreeForFile(RootPath, FileName, sBuffer)
It seems to work fine on Win 98 and 2000, but on NT machines with Sp5 it returns 0 indicating that the file does not exist, but it does.
What is wrong and how can I correct it?
jim mcnamara
Nov 2nd, 2001, 08:53 AM
You declared the api like this? The ByVal part is important.
Private Declare Function SearchTreeForFile Lib "imagehlp.dll" _
(ByVal sRootPath As String, _
ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Boolean
You call it like this
Public Function ff(sDrive As String, sFile As String) As String
Dim str As String
str = Space(MAX_PATH)
If SearchTreeForFile(sDrive2Scan, sFile2Find, sResult) Then
ff = Left(sResult, InStr(str, vbNullChar) - 1)
Else
ff = "File not found: " & Err.LastDllError
End If
End Function
Innofin
Nov 5th, 2001, 06:36 AM
When I do it like this the SearchTreeForFile returns false, but the file does exist on the sDrive2Scan.
Dim str As String
str = Space(MAX_PATH)
If SearchTreeForFile(sDrive2Scan, sFile2Find, sResult) Then
ff = Left(sResult, InStr(str, vbNullChar) - 1)
Else
ff = "File not found: " & Err.LastDllError
End If
This works on Win 2000 and 9X, but not on Win NT SP5.
What could be the error?
jim mcnamara
Nov 5th, 2001, 11:12 AM
Folder protections prevent scans.
When you have Execute access you can get a file if you know the name beforehand. Otherwise you have to have Read access to the folder to scan it.
Go in as admin and see if your code works on NT. It has to be protections, since Win2K is really NT 5.0
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.