Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now