Solved

VB DIR command and FSO file exists not working in vb6 with Windows Vista 64 bit

Posted on 2011-02-23
2
2,401 Views
Last Modified: 2012-05-11
When I loop through a list of driver paths that I enumerated from the registry and test if they exists using FSO, it works fine in Windows XP, but not in Vista 64 bit. I created a simple Visual Basic 6 exe with 6 lines of code (see code below). It works in Windows XP, but in Windows Vista 64 bit, it shows that the file does not exist. Here is the odd part. Two of the roughly 100 drivers paths that are enumerated show that they exist. Files that are not in the system32 folder also work fine. Also, if I create a vbscript with the same code, it works fine. Seems like maybe a bug, but not sure. And I have verified multiple that the file does truly exist. I decided to use VB6's built-in DIR command, but it does the same thing. Not sure what to do here.
Private Sub Command1_Click()
    'THIS CODE WORKS IN XP OR VBSCRIPT, BUT FAILS
    'WHEN RAN IN VISUAL BASIC 6 WITH VISTA 64 BIT
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'A VERIFIED FILE
    sFile = "C:\windows\system32\drivers\smb.sys"
    If objFSO.FileExists(sFile) Then
        MsgBox "file exists"
    Else
        MsgBox "File does not exist."
    End If
    'IN VISTA 64 BIT, THE ANSWER IS ALWAYS NOT EXIST
End Sub

Private Sub Command1_Click()
    'THIS CODE WORKS IN XP OR VBSCRIPT, BUT FAILS
    'WHEN RAN IN VISUAL BASIC 6 WITH VISTA 64 BIT
    'A VERIFIED FILE
    sFile = "C:\windows\system32\drivers\smb.sys"
    If Dir(sFile) <> "" Then
        MsgBox "file exists"
    Else
        MsgBox "File does not exist."
    End If
    'IN VISTA 64 BIT, THE ANSWER IS ALWAYS NOT EXIST
End Sub

Open in new window

0
Comment
Question by:advcom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 34960165
On 64 bit PC look in the WOW64 folder rather than the system32

0
 

Author Comment

by:advcom
ID: 35033889
That does seem to be the issue. I figured out that if I use WMI to get file properties, it seems to be able to get 32 and 64 bit properties just fine.
Function getProperties(strFilePath)
    strFilePath = Replace(strFilePath, "\", "\\")
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
    Set colFiles = objWMIService.ExecQuery("Select * from CIM_Datafile Where name = '" & strFilePath & "'")
    
    If colFiles.Count > 0 Then
        strFileExist = "yes"
        strFilePath = Replace(strFilePath, "\\", "\") 'ADD ESCAPE CHARACTER FOR WMI
        For Each objFile In colFiles
            If objFile.fileSize <> "" Then fileSize = objFile.fileSize
            If objFile.Manufacturer <> "" Then fileCompany = objFile.Manufacturer
            If objFile.Version <> "" Then fileVersion = objFile.Version
        Next
    Else
        strFileExist = "no"
            fileCreateDate = ""
            fileCompany = ""
            fileVersion = ""
            fileSize = ""
    End If
End Function

Open in new window

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question