Results 1 to 3 of 3

Thread: Getting the users windows & system's dir... STILL UNRESOLVED

  1. #1

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    4.                                                                                         ByVal nSize As Long) _
    5.                                                                                         As Long
    6. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    7.                                                                                           ByVal nSize As Long) _
    8.                                                                                           As Long
    9. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, _
    10.                                                                           ByVal lpBuffer As String) _
    11.                                                                           As Long
    12.  
    13. Private Const DIR_SYS  As Byte = 0
    14. Private Const DIR_WIN  As Byte = 1
    15. Private Const DIR_TEMP As Byte = 2
    16.  
    17. Private Function GetPath(ByVal PathType As Byte) As String
    18.  
    19.     GetPath = Space$(255)
    20.  
    21.     Select Case PathType
    22.         Case DIR_SYS:  Call GetSystemDirectory(GetPath, Len(GetPath))
    23.         Case DIR_WIN:  Call GetWindowsDirectory(GetPath, Len(GetPath))
    24.         Case DIR_TEMP: Call GetTempPath(Len(GetPath), GetPath)
    25.     End Select
    26.  
    27. End Function
    28.  
    29. Private Sub Command1_Click()
    30.    
    31.     MsgBox GetPath(DIR_WIN)
    32.     MsgBox GetPath(DIR_SYS)
    33.     MsgBox GetPath(DIR_TEMP)
    34.    
    35. 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.

  2. #2
    Junior Member
    Join Date
    Jan 2003
    Posts
    27
    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!
    -wat

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    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:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    4.                                                                                         ByVal nSize As Long) _
    5.                                                                                         As Long
    6. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    7.                                                                                           ByVal nSize As Long) _
    8.                                                                                           As Long
    9. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, _
    10.                                                                           ByVal lpBuffer As String) _
    11.                                                                           As Long
    12.  
    13. Private Const DIR_SYS  As Byte = 0
    14. Private Const DIR_WIN  As Byte = 1
    15. Private Const DIR_TEMP As Byte = 2
    16.  
    17. Private Function GetPath(ByVal PathType As Byte) As String
    18. Dim ret As Long
    19. Dim sSave As String
    20.  
    21.     sSave = Space(255)
    22.  
    23.     Select Case PathType
    24.         Case DIR_SYS
    25.             ret = GetSystemDirectory(sSave, 255)
    26.         Case DIR_WIN
    27.             ret = GetWindowsDirectory(sSave, 255)
    28.         Case DIR_TEMP
    29.             ret = GetTempPath(255, sSave)
    30.     End Select
    31.    
    32.     'Remove all the unused characters.
    33.     sSave = Left(sSave, ret)
    34.    
    35.     If Right(sSave, 1) <> "\" Then sSave = sSave & "\"
    36.    
    37.     GetPath = sSave
    38.  
    39. End Function
    40.  
    41. Private Sub Command1_Click()
    42.  
    43.     MsgBox GetPath(DIR_WIN)
    44.     MsgBox GetPath(DIR_SYS)
    45.     MsgBox GetPath(DIR_TEMP)
    46.    
    47. 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
  •  



Click Here to Expand Forum to Full Width