[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

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
0
LeXien
Asked:
LeXien
  • 4
  • 3
  • 2
  • +2
1 Solution
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
É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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now