Solved

VB5 - Locating system root directory.

Posted on 1998-07-10
5
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

717 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