Application.FileSearch on Server 2008 R2

T

TomT

I am using VBA (in an MS Access 2003 app) to use Application.FileSearch to
locate a user's Acrobat Reader executable. I have developed this and tested
on a Win 7 x64 machine, and it works perfectly. However when I test it on a
Windows 2008 R2 system I get a very odd behavior.

In the code, I use environment variables to find the location of Program
Files, and build a string for the .LookIn property of the
Application.FileSearh.NewSearch object.

Here is the code:

Public Function FindAcrobatReader() As String
On Error GoTo Err_FindAcrobatReader
' Comments :
' Parameters :
' Created : 2/8/2010 1:04:28 PM
' Modified :
' Returns :
' --------------------------------------------------

Dim i As Integer
Dim acrobatFileAndPath As String

acrobatFileAndPath = GetEnvironVar("ProgramFiles")
acrobatFileAndPath = acrobatFileAndPath & "\Adobe"

With Application.FileSearch

.NewSearch
.LookIn = acrobatFileAndPath
.SearchSubFolders = True
.FileName = "AcroRd32.exe"
.MatchTextExactly = True
.filetype = msoFileTypeAllFiles

End With

With Application.FileSearch

If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count

FindAcrobatReader = .FoundFiles(i)

Next i

Else

MsgBox "There were no files found."

End If

End With

'Error Handler
Exit_FindAcrobatReader:
Exit Function

Err_FindAcrobatReader:
If Err.Number <> 0 Then
Select Case Err.Number

Case Else
MsgBox "Error:" & Err.Number & vbCrLf & Err.Description,
vbCritical, "FindAcrobatReader Error"
End Select
End If
Resume Exit_FindAcrobatReader
End Function

On the Server system, (even if I hardcode in the .LookIn path), the .LookIn
always resets itself to my documents folder (e.g. c:\userst\tomt\documents),
and of course the file I'm looking for is not there.

I'm guessing this has something to do with Server 2008 R2 security, but I
don't know what to look for, or where.

Any help would be greatly appreciated
 
C

Charles Wang [MSFT]

Hi Tom,
Since this is an Office VBA development issue, to get the best assistance,
please post a new post at this community:
public.office.developer.vba

Thank you!

Best regards,
Charles Wang
 
T

TomT

Ok, I posted in the goup you suggested. BTW, I'm not getting notification
when there is a reply...

Thanks
 
T

TomT

Thanks Stefan

Stefan Hoffmann said:
hi Tom,

I'm guessing this has something to do with Server 2008 R2 security, but I
don't know what to look for, or where.

Any help would be greatly appreciated
I would use another approach:

http://vbnet.mvps.org/index.html?code/system/findexecutable.htm

Or read it from

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Adobe\Acrobat
Reader\9.0\InstallPath]
@="C:\\Program Files (x86)\\Adobe\\Reader 9.0\\Reader"


mfG
--> stefan <--
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top