Solved

GetSystemDirectory .

Posted on 2000-05-03
6
214 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
ID: 2774405
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2774417
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
ID: 2774420
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Erick37
ID: 2774422
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
ID: 2774427
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
ID: 2774497
Thank you very much.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

679 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