Solved

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

Posted on 2011-02-23
2
2,345 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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