Solved

VB5 - Locating system root directory.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now