[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

GetSystemDirectory .

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
rng
Asked:
rng
1 Solution
 
RuchiCommented:
This should solve your problem...
http://www.ozemail.com.au/~measlea/api/sysdir.htm
0
 
AzraSoundCommented:
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
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!

 
Erick37Commented:
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
 
RuchiCommented:
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
 
rngAuthor Commented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now