?
Solved

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

Posted on 2011-02-23
2
Medium Priority
?
2,451 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

764 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