Results 1 to 7 of 7

Thread: Dos Way

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    138

    Dos Way

    I have this path C:\Documents and Settings\System Administrator
    as u know dos reads it in this way C:\Docume~1\System~1>

    how can I let my application read the path in the dos way using app.path

    thanks

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Dos Way

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    4.  
    5. Public Function GetShortPath(strFileName As String) As String
    6.     'KPD-Team 1999
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Dim lngRes As Long, strPath As String
    10.     'Create a buffer
    11.     strPath = String$(165, 0)
    12.     'retrieve the short pathname
    13.     lngRes = GetShortPathName(strFileName, strPath, 164)
    14.     'remove all unnecessary chr$(0)'s
    15.     GetShortPath = Left$(strPath, lngRes)
    16. End Function
    17.  
    18. Private Sub Form_Load()
    19.     MsgBox GetShortPath(App.Path)
    20. End Sub

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Dos Way

    so is your question that you want to convert App.Path into the short path version? if so:
    VB Code:
    1. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" ( _
    2.     ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    3.  
    4. Private Function GetShortPath(strFileName As String) As String
    5.     'KPD-Team 1999
    6.     'URL: [url]http://www.allapi.net/[/url]
    7.     'E-Mail: [email][email protected][/email]
    8.     Dim lngRes As Long, strPath As String
    9.     'Create a buffer
    10.     strPath = String$(165, 0)
    11.     'retrieve the short pathname
    12.     lngRes = GetShortPathName(strFileName, strPath, 164)
    13.     'remove all unnecessary chr$(0)'s
    14.     GetShortPath = Left$(strPath, lngRes)
    15. End Function
    16.  
    17. Private Sub Form_Load()
    18.     MsgBox GetShortPath(App.Path)
    19. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    138

    Re: Dos Way

    can u try this plz ?
    MsgBox GetShortPath(App.Path & "\" & App.EXEName & ".exe")
    it doesn't return anything :S

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Dos Way

    works absolutely fine for me:

    C:\PROGRA~1\MICROS~4\VB98\Project1.exe

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Dos Way

    change to this

    MsgBox GetShortPath(App.Path) & "\" & App.EXEName & ".exe"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Dos Way

    Quote Originally Posted by westconn1
    change to this

    MsgBox GetShortPath(App.Path) & "\" & App.EXEName & ".exe"
    no don't do that as the exe name may also need to be shortened.

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