Solved

VB5 - Locating system root directory.

Posted on 1998-07-10
5
174 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 70
MS Date Picker 64 bit 32 bit issue 12 53
MsgBox 4 61
VB6 ListBox Question 4 44
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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