Solved

GetSystemDirectory .

Posted on 2000-05-03
6
209 Views
Last Modified: 2010-05-02
Here is a portion of my program.

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

Dim l as long, strDir as string
l = GetSystemDirectory(strDir, 20)


I want to use GetSystemDirectory to find the path to the system directory. However, it return 0 (0 means function call fail). I don't know why ? Is my program code wrong ?
Does any other function do the same?? I want to find a path to the system directory.
Please help.

Regards,

Raymond
0
Comment
Question by:rng
6 Comments
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
This should solve your problem...
http://www.ozemail.com.au/~measlea/api/sysdir.htm
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
Comment Utility
Public Const MAX_PATH = 260

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


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


An example of how to use this function:

Call MsgBox("The Windows System directory is " & _
GetSystemPath, vbInformation)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Private Sub Command1_Click()
    Dim lRet As Long
    Dim sBuffer As String
    sBuffer = String(260, Chr(0))
    lRet = GetSystemDirectory(sBuffer, 260)
    sBuffer = Left(sBuffer, lRet)
    Debug.Print sBuffer
End Sub
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
From http://members.tripod.com/cuinl/Tips/systemdir.htm

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :

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

'Insert this code to your form:

Private Sub Form_Load()
Dim S As String
S = String(80, 0)
Call GetSystemDirectory(S, 80)
UserName = Left(S, InStr(S, Chr(0)) - 1)
MsgBox (S)
End Sub
0
 

Author Comment

by:rng
Comment Utility
Thank you very much.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 77
Excel object stays open 19 64
Updates not working for MS Windows 7 12 122
Add a task in Outlook from access 11 32
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…
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.
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…
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…

762 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

8 Experts available now in Live!

Get 1:1 Help Now