System File Paths

Hi,

I need to find out where the following paths of files are without hard-coding it. Some systems may have relocated these important system files, i need a dynamic way to locate them.

Preferbly using API rather than searching the HD for them. FAST! LESS THAN 0.5 Seconds like...


Files are:
Win.ini
System.ini
Autoexec.bat
Config.sys


thanks
POINTS WILL BE INCREASED TO 40 ONCE A GOOD ANSWER IS PROVIDED - HATE WASTING POINTS FOR AN INCORRECT ANSWER! THANX
LeXienAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hesCommented:
In a module declare

Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long


In your code use the following:

1) For win & system.ini

Dim RetVal, RootDir, WinDir$
WinDir = Space(144)
RetVal = GetWindowsDirectory(WinDir, 144)
WinDir = Trim(WinDir) & "\"

This will give you your windows directory, for the other two
RootDir = Left(WinDir,3)
0
Éric MoreauSenior .Net ConsultantCommented:
Put this code in a file and save it as a form.

____ BEGINNING OF THE FORM _____

VERSION 5.00
Begin VB.Form frmFindFile
   Caption         =   "Form1"
   ClientHeight    =   1245
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3000
   LinkTopic       =   "Form1"
   ScaleHeight     =   1245
   ScaleWidth      =   3000
   StartUpPosition =   3  'Windows Default
   Begin VB.DirListBox Dir1
      Height          =   315
      Left            =   240
      TabIndex        =   2
      Top             =   840
      Visible         =   0   'False
      Width           =   2535
   End
   Begin VB.DriveListBox Drive1
      Height          =   315
      Left            =   240
      TabIndex        =   1
      Top             =   120
      Width           =   2625
   End
   Begin VB.FileListBox File1
      Height          =   285
      Left            =   240
      Pattern         =   "*.txt"
      TabIndex        =   0
      Top             =   480
      Visible         =   0   'False
      Width           =   2595
   End
End
Attribute VB_Name = "frmFindFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public mlngFound As Long
Public mstrDest As String
Public mstrDrive As String
Public mstrPattern As String

Public Sub Command1_Click()
    Screen.MousePointer = vbHourglass
   
    File1.Pattern = mstrPattern
    Drive1.Drive = mstrDrive
    Call ScanDrives(mstrDrive & ":\")
   
    Screen.MousePointer = vbDefault
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1
End Sub

Private Sub File1_PathChange()
Dim lngI As Long
   
    For lngI = 0 To File1.ListCount - 1
        If gusrApplication.strDirLastVersion <> UCase$(Dir1) Then
            mstrDest = Dir1
            mlngFound = mlngFound + 1
        End If
    Next lngI
End Sub

Private Sub ScanDrives(ds_Dir As String)
Dim lngI As Long
Dim arrPath() As String
   
   'Se positionner sur le répertoire
   Dir1 = ds_Dir
   
   ReDim Preserve arrPath(Dir1.ListCount)
   
   ' Chercher tous les sous-répertoire du présent répertoire
   For lngI = 0 To Dir1.ListCount - 1
      If Not UCase$(Right$(Dir1.List(lngI), 6)) = "BACKUP" Then
        arrPath(lngI) = Dir1.List(lngI)
      End If
   Next lngI

   'Parcourir les répertoire
   For lngI = 0 To Dir1.ListCount - 1
      If Not arrPath(lngI) = "" Then Call ScanDrives(arrPath(lngI))
   Next lngI
   
   'Libérer le array de la mémoire
   Erase arrPath
End Sub

____ END OF THE FORM _____

Now to use it:

On another form:
frmFindFile.mlngFound = 0
frmFindFile.mstrDrive = "C"
frmFindFile.mstrPattern = "CALC.EXE"
frmFindFile.Command1_Click
       
Select Case frmFindFile.mlngFound
   Case 0
      MsgBox "File not found"
   Case 1
      MsgBox "File found at: " & frmFindFile.mstrDest
   Case Else
      MsgBox "The file is more than one place!!!"
End Select

0
LeXienAuthor Commented:
I need to find/locate these files:

sytem.ini
win.ini
config.sys
autoexec.bat


I said that i would prefer not having a search utility. Isn't there any dymanic way which is very fast and will just return the path of the files? Surely Microsoft don't use some searh util' to search you HD for the config.sys or one of those other files.
Is it actually possible to have these system files anywhere else - i know that the win.ini and system.ini go whereever the Windows directory is. But what about autoexec.bat and config.sys are these always on a root drive?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Éric MoreauSenior .Net ConsultantCommented:
You can retreive the Windows directory like hes wrote! What do you want more?
0
LeXienAuthor Commented:
I know how to retreive the Windows and System directorys. But i also need to retreive where the Autoexec.bat and Config.sys files are. Are they always in a root path?
And are the Win.ini and System.ini always in the Windows directory?
0
Éric MoreauSenior .Net ConsultantCommented:
They must be there to be used when Windows start.
0
plasmatekCommented:
OK, I assume you know how to do win.ini and system.ini - they are easy. Get windows directory using the API then add on the filenames.

Dim myrootdrive As String
Dim autoexec As String
Dim config As String
myrootdrive = Left(Environ("comspec"), 3)
autoexec = myrootdrive & "autoexec.bat"
config = myrootdrive & "config.sys"


Voila!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KDivadCommented:
The windows folder can also be gotten using Environ$("windir").
0
LeXienAuthor Commented:
yeah - im gunna accept this answer in a bit.

Only, isn't there any other way to retreive the root drive?
0
KDivadCommented:
Excuse me if I sound startled, but are you looking for something harder to use? There can't be anything easier than:
Left$(Environ$("windir"), 1)
0
LeXienAuthor Commented:
hanks
0
plasmatekCommented:
I thought u were increasing the points to 40?

And why did u give me a C? That was perfect code!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.