Solved

VB5 - Locating system root directory.

Posted on 1998-07-10
5
169 Views
Last Modified: 2010-05-18
How do you determine what directory the system root while in a VB 5 app?  
(i.e.  the equivalent return value of the %systemroot%   intrinsic command which returns  e.g.  C:\WINDOWS   or   C:\WINNT   or C:\WINNT35. )
0
Comment
Question by:nelchr
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 50 total points
ID: 1465443
This will do it:

Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Dim str as String
Dim ret as Integer
str = space$(256)
ret = GetSystemDirectory (str, len(str))
str = Left$(str,ret)

Good luck!
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1465444
nelchr,
Try this.  
regards
Dalin


' Declarations

Public Const MAX_PATH = 260

Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal _
nSize As Long) As Long
         

' Function

Public Function GetSystemPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetSystemDirectory(strFolder, MAX_PATH)
If lngResult <> 0 Then
    GetSystemPath = Left(strFolder, InStr(strFolder, _
    Chr(0)) - 1)
Else
    GetSystemPath = ""
End If
End Function
         

'Use

Call MsgBox("The Windows System directory is " & _
GetSystemPath, vbInformation)          
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1465445
alamo,  I guess my typing is too slow...
Regards
0
 
LVL 6

Expert Comment

by:alamo
ID: 1465446
Sorry, Dalin. By the way, it's worth pointing out that you don't need to do if .. else and an instr since the return value is the length (in characters) of the string. There are a number of API functions like this.
0
 

Author Comment

by:nelchr
ID: 1465447
Looks good.  Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now