|
-
Feb 8th, 2003, 06:35 AM
#1
Thread Starter
Fanatic Member
Getting the users windows & system's dir... STILL UNRESOLVED
Here is some code i'm using to read the user's windows, system & temp directory... but i'm having some problems...
VB Code:
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) _
As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) _
As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Const DIR_SYS As Byte = 0
Private Const DIR_WIN As Byte = 1
Private Const DIR_TEMP As Byte = 2
Private Function GetPath(ByVal PathType As Byte) As String
GetPath = Space$(255)
Select Case PathType
Case DIR_SYS: Call GetSystemDirectory(GetPath, Len(GetPath))
Case DIR_WIN: Call GetWindowsDirectory(GetPath, Len(GetPath))
Case DIR_TEMP: Call GetTempPath(Len(GetPath), GetPath)
End Select
End Function
Private Sub Command1_Click()
MsgBox GetPath(DIR_WIN)
MsgBox GetPath(DIR_SYS)
MsgBox GetPath(DIR_TEMP)
End Sub
It displays the directories perfectly... but I can't input the findings into a string. IE... i have tried this...
open DIR_WIN & "\test.txt" for append as #1
& this...
windowsdir = DIR_WIN
windowsdir = getpath(DIR_WIN)
but the string is then totally corrupt, and unusable.
Any idea's peeps... i'm struggling like hell!
Regards,
Paul.
Last edited by VisionIT; Feb 8th, 2003 at 08:46 AM.
-
Feb 8th, 2003, 09:30 AM
#2
Junior Member
thats rather strange... i wasn't sure of what you were talking about until i tried it myself and i've never seen that before. Anways i might be able to help, but i'm not sure if its the solution you're looking for. You can try this though...
Code:
Private Sub Command2_Click()
Dim windowsdir$
windowsdir$ = GetPath(DIR_WIN)
Text1.Text = windowsdir$
windowsdir$ = Text1.Text
MsgBox windowsdir$ & "\test.txt"
End Sub
As you can see, it sets the text to a textbox and then back to the string... if this is what you are looking for i suggest you add it to the GetPath Function to save some time. Good luck!
-
Feb 8th, 2003, 09:32 AM
#3
I changed your code a little bit but I think the main problem was you did not remove the null characters from the string.
VB Code:
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) _
As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) _
As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Const DIR_SYS As Byte = 0
Private Const DIR_WIN As Byte = 1
Private Const DIR_TEMP As Byte = 2
Private Function GetPath(ByVal PathType As Byte) As String
Dim ret As Long
Dim sSave As String
sSave = Space(255)
Select Case PathType
Case DIR_SYS
ret = GetSystemDirectory(sSave, 255)
Case DIR_WIN
ret = GetWindowsDirectory(sSave, 255)
Case DIR_TEMP
ret = GetTempPath(255, sSave)
End Select
'Remove all the unused characters.
sSave = Left(sSave, ret)
If Right(sSave, 1) <> "\" Then sSave = sSave & "\"
GetPath = sSave
End Function
Private Sub Command1_Click()
MsgBox GetPath(DIR_WIN)
MsgBox GetPath(DIR_SYS)
MsgBox GetPath(DIR_TEMP)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|