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
Solved

VB5 - Locating system root directory.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
How to create a duplicate finder Application 9 122
How to debug this code 7 64
Copy a row 12 64
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

861 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