Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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