Solved

GetSystemDirectory .

Posted on 2000-05-03
6
219 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
[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
6 Comments
 
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

696 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