Problems with command line arguments

Posted on 2006-04-05
Last Modified: 2010-04-07
Hi guys,
I'm having problems with command line arguments. When I double click on a file (p1.gemr) on my Desktop, my application uses the following statement to read the command line parameters, wanting to extract the above file name:

     sFileName = Replace(Command, """", "")

Instead of getting a proper file path+name I get what appears to be a truncated name, e.g.


I imaging it has something to do with short file names but I don't know how to check/set that.
Does anyone have any ideas as to how to solve my problem?

Question by:gem56
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    to get the application path, use

    Author Comment

    What I'm really after is the name of the file that was opened, so that my application can read the contents.

    LVL 4

    Expert Comment

    have you tried opening it using exactly what was returned.  i.e., even though we don't know what "DOCUME~1" really refers to, it should still be a valid path.  Unfortunately I don't have a system I can test this on, so it's just a guess.

    LVL 28

    Accepted Solution

    Have you tried converting the short filename to a longfilename?

    Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long

    Private Function fGetLongPath(strShortPath As String) As String
    Dim strLongPath As String, lngRet As Long
    strLongPath = Space$(255)
    lngRet = GetLongPathName(strShortPath, strLongPath, 255)
    fGetLongPath = Left$(strLongPath, lngRet)
    End Function

    Private Sub Command1_Click()
       MsgBox fGetLongPath(sFileName)
    End Sub

    Author Comment

    Thanks everyone for your input, especially vinnyd79 as that did the trick.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    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.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now