locked
Extracting application name + _splitpath RRS feed

  • Question

  • We are using _splitpath function to extract application name from complete command line received.

    For example if the command line received is:

    c:/Program Files/Test/test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    Then desired application name is:

    test.exe

    But _splitpath is not providing proper results when command line is something similar to one mentioned above. Also _splitpath causes crashes if the commend line parameter received is too huge.

    Is there any were any alternative to extract the application name. Any other method or function ?


    • Edited by Anshul Jaiswal Wednesday, April 13, 2011 6:01 AM spelling mistakes.
    Wednesday, April 13, 2011 5:59 AM

Answers

  • Hi All,

    I developed code to extract the application name from command line. The below code will give us the desired app name, but this is not a full proff solution. I can say it will be working in 70-80% cases but not 100% solution. Must try :

    BOOL ExtractAppPathNName(CString strCommandLine, CString& strrefAppPath, CString& strrefAppName)
    {
    //---
    BOOL bRet = FALSE;
    BOOL bIsCont = FALSE;
    
    int iTemp = 0;
    int iIndex = 0, iPrevIndex = 0;
    int iIndexTemp = 0;
    int iLastIndex = 0;
    int iCount = 0;
    int iFirst = -1;
    int nCount = -1;
    
    CString strLeft = _T("");
    CString strRight = _T("");
    CString strTemp = _T("");
    CString strTemp1 = _T("");
    
    CString strLocalCmdLine = _T("");
    CString strLocalAppPath = _T("");
    CString strLocalAppName = _T("");
    //---
    
    try
    {
    //Validating input parameters.
    if(strCommandLine && strrefAppPath && strrefAppName)
    {
    strrefAppPath.Empty();
    strrefAppName.Empty();
    
    //Getting local copy of Command Line.
    strLocalCmdLine.Empty();
    strLocalCmdLine = strCommandLine;
    
    //Validating command line parameter.
    if(!strLocalCmdLine.IsEmpty())
    {
    //Removing "(double-quote).
    strLocalCmdLine.Remove(_T('"'));
    
    iIndex = strLocalCmdLine.FindOneOf(_T("/*?\"<>|"));
    if(-1 != iIndex)
    {
    strLocalCmdLine = strLocalCmdLine.Left(iIndex);
    }
    
    iIndex = strLocalCmdLine.Find(_T(":"), 2);
    if(-1 != iIndex)
    {
    strLocalCmdLine = strLocalCmdLine.Left(iIndex);
    }
    
    //Extracting Application Path.
    iIndex = 0;
    bIsCont = TRUE;
    //Continue the loop.
    while(bIsCont)
    {
    if((0 <= iIndex) && (strLocalCmdLine.GetLength() > iIndex))
    {
    iPrevIndex = iIndex;
    //Searching for any occurance of a '.'
    iIndex = strLocalCmdLine.Find(_T('.'), iIndex);
    
    if(-1 != iIndex)
    {
    //Get the sub string on left side of '.'
    iFirst = 0;
    nCount = iIndex;
    strLeft.Empty();
    strLeft = strLocalCmdLine.Mid(iFirst, nCount);
    
    iFirst = nCount;
    
    nCount = strLocalCmdLine.GetLength() - nCount;
    
    strTemp.Empty();
    strTemp = strLocalCmdLine.Right(nCount);
    
    strTemp1.Empty();
    if(1 < strTemp.GetLength())
    strTemp1 = strTemp.Mid(1);
    else
    strTemp1 = strTemp;
    
    iPrevIndex = iIndex;
    iIndex = strTemp1.FindOneOf(_T(".\\ /"));
    if(-1 != iIndex)
    {
    iIndex += 1;
    
    strTemp1.Empty();
    strTemp1 = strTemp.GetAt(iIndex);
    
    iIndex += iFirst;
    
    if((!strTemp1.Compare(_T(" "))) || 
    (!strTemp1.Compare(_T("/"))))
    {
    if(iIndex > iFirst)
    {
    //Get the sub string on right side of '.'
    //Upto the next occurance of a \(backslash) or
    //space or a /(fordwardslash)
    nCount = iIndex-iFirst;
    strRight.Empty();
    strRight = strLocalCmdLine.Mid(iFirst, nCount);
    
    if((0 == strRight.CompareNoCase(_T(".exe"))) ||
      (0 == strRight.CompareNoCase(_T(".msi"))) ||
      (0 == strRight.CompareNoCase(_T(".bat"))))
    {
    bIsCont = FALSE;
    //Discontinue the loop.
    }
    else
    {
    strRight.Empty();
    }
    }
    }
    }
    
    if((!strLeft.IsEmpty()) && (!strRight.IsEmpty()))
    {
    strLocalAppPath.Empty();
    strLocalAppPath = strLeft + strRight;
    }
    }
    else
    {
    if(iPrevIndex)
    {
    strTemp.Empty();
    strTemp = strLocalCmdLine.Mid(iPrevIndex+1);
    //strTemp.TrimLeft();
    //strTemp.TrimRight();
    
    iIndex = strTemp.FindOneOf(_T("\\ /"));
    if(-1 != iIndex)
    {
    strTemp1.Empty();
    strTemp1 = strTemp.GetAt(iIndex);
    
    iIndex += 1;
    iIndex += iPrevIndex;
    iPrevIndex = iIndex;
    
    if((!strTemp1.Compare(_T(" "))) || 
    (!strTemp1.Compare(_T("/"))))
    iIndex = -1;
    }
    else
    {
    iPrevIndex = strLocalCmdLine.GetLength();
    iIndex = -1;
    }
    }
    else
    {
    iPrevIndex = strLocalCmdLine.GetLength();
    iIndex = -1;
    }
    }
    }
    else
    {
    if(iPrevIndex)
    {
    iIndex = strLocalCmdLine.Find(_T(':'), iPrevIndex);
    if(-1 != iIndex)
    {
    nCount = iIndex-1;
    strLocalAppPath.Empty();
    strLocalAppPath = strLocalCmdLine.Left(nCount);
    }
    else
    {
    iIndex = strLocalCmdLine.Find(_T(' '), iPrevIndex);
    if(-1 != iIndex)
    {
    nCount = iIndex;
    }
    else
    {
    nCount = strLocalCmdLine.GetLength();
    }
    
    if(0 <= nCount)
    strLocalAppPath = strLocalCmdLine.Left(nCount);
    }
    }
    else
    strLocalAppPath = strLocalCmdLine;
    
    //Discontinue the loop.
    bIsCont = FALSE;
    }
    }
    
    //Checking for application name in application path.
    if(!strLocalAppPath.IsEmpty())
    {
    iIndex = strLocalAppPath.ReverseFind(_T('\\'));
    if(-1 != iIndex)
    {
    iLastIndex = strLocalAppPath.GetLength();
    
    if(iLastIndex > iIndex)
    iCount  = iLastIndex - iIndex -1;
    
    iIndex += 1;
    }
    else
    {
    iIndex = 0;
    iCount = strLocalAppPath.GetLength();
    }
    
    if(0 > iCount)
    iCount = 0;
    
    strLocalAppPath.TrimLeft();
    strLocalAppPath.TrimRight();
    
    //Extracting for application name in application path.
    strLocalAppName.Empty();
    strLocalAppName = strLocalAppPath.Mid(iIndex, iCount);
    
    strLocalAppName.TrimLeft();
    strLocalAppName.TrimRight();
    
    //Assigning result to out parameters.
    strrefAppPath.Empty();
    strrefAppPath = strLocalAppPath;
    
    strrefAppName.Empty();
    strrefAppName = strLocalAppName;
    
    //Success.
    bRet = TRUE;
    } 
    }
    }
    }
    catch(...)
    {
    }
    
    return bRet;
    }




    • Marked as answer by Anshul Jaiswal Wednesday, October 10, 2012 1:46 PM
    • Edited by Anshul Jaiswal Wednesday, October 10, 2012 7:03 PM correction
    Wednesday, October 10, 2012 1:26 PM

All replies

  • Call GetModuleFileName() with '0' as a module handle.

     

     Usage:

    TCHAR exepath[MAX_PATH];  
    if(0 != GetModuleFileName(0, exepath, MAX_PATH))
     
       
    MessageBox(_T("Error!"));
      
    MessageBox(exepath, _T(" Is application name"));
     


    Wednesday, April 13, 2011 6:05 AM
  • As I mentioned above I have the application name with me, but that application name is with the comman line parameters, GetModuleFilename will provide the currrent modules file path.

    But I need to seperate out the application name from complete command line path.

    Once again

    For example if command line parametes is:

    c:/Program Files/Test/test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    then desired application name is :

    test.exe

    Wednesday, April 13, 2011 6:18 AM
  • Is there any method to seperate out the application path from its command line parameters.

    For example if complete command line is:

    c:/Program Files/Test/test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    then we need to seperate out

    application path:

    c:/Program Files/Test/test.exe

    and command line parameters:

    /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    Once we get the application path then we can use PathStripPath function to extract application name(test.exe in our example).

    Is it possible to extract the application path and its command line parameters?

     




    Wednesday, April 13, 2011 6:22 AM
  •  Use

    errno_t _splitpath_s(
    
     const char * path,
    
     char * drive,
    
     size_t driveNumberOfElements,
    
     char * dir,
    
     size_t dirNumberOfElements,
    
     char * fname,
    
     size_t nameNumberOfElements,
    
     char * ext, 
    
     size_t extNumberOfElements
    
    );
    
    
    
    
    //returns Zero if successful; an error code on failure. 

    Find what the errno_t you are getting when unsuccessful

     

     


    Knowledge is like light; It spreads only when you have clear and transparent mind.
    Wednesday, April 13, 2011 6:38 AM
  • As I mentioned above in examples that _splitpath does not work properly if the application path cointains command line parameters such as:

    c:\Program Files\Test\test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    In this case it will return application name(fname) as :

    version:13.0

    and ext :

    .1783

    Is there any other way?

     




    Wednesday, April 13, 2011 6:44 AM
  • Hi,

    c:/Program Files/Test/test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    then we need to seperate out

    application path:

    c:/Program Files/Test/test.exe

    and command line parameters:

    /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    Once we get the application path then we can use PathStripPath function to extract application name(test.exe in our example).

    Is it possible to extract the application path and its command line parameters?

     

     

    You can use GetModuleFileName() for get  c:/Program Files/Test/test.exe application path. You can get your command line parameters from main function argument.

     

    Microsoft recommended to use _s funcations for security reason. So, you _splitpath_s for get application name test.exe


    Thanks and Regards Selvam http://www15.brinkster.om/selvamselvam/
    Wednesday, April 13, 2011 6:47 AM
  • Thank you for reply Selvam,

    The test.exe is not my current proceess, In my process say myApp.exe I am receiving the command line parameters for running apps by some other way, hence GetModuleFileName does not works for me.

    Wednesday, April 13, 2011 6:56 AM
  • hum.... ok

    Now, your application looks like Then c:/myApp.exe c:/Program Files/Test/test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783 . IS it? Now, you can't use space as separator. Because, The <Program Files> has space. You can get aruguments like the following will resolve your issue.

     

    c:/myApp.exe -AppName c:/Program Files/Test/test.exe -Args /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

     

    Otherwise, it is very difficult for assumes something which will come from user. Otherwise, you can search .exe in arguments and take the position and get string from o'th pos to .exe position.


    Thanks and Regards Selvam http://www15.brinkster.om/selvamselvam/
    Wednesday, April 13, 2011 7:06 AM
  • You can check the CPath class. It has functions to get thefile name, the
    path, etc. It even has a function called RemoveArgs, which removes the
    command-line arguments, leaving you with the path alone. If you can use
    it, I think that could solve your problem.
     
    If you can't use CPath, you can use ::PathRemoveArgs, ::PathStripPath,
    etc. which are what CPath calls to do its work.
     
     
    Wednesday, April 13, 2011 7:13 AM
  • Error compiling code which include header atlpath.h for CPath.

    Error is:

    Error 1 error C2039: 'PathAddBackslashA' : is not a member of '`global namespace'' d:\program files\microsoft visual studio 8\vc\atlmfc\include\atlpath.h 36 


    Wednesday, April 13, 2011 8:01 AM
  • I think you have to include both shlwapi.h and atlpath.h
     
    • Proposed as answer by Hans Gälldin Wednesday, April 13, 2011 9:48 AM
    Wednesday, April 13, 2011 8:08 AM
  • Thanks, I am able to complie the code.

    But for application path :

    c:\Program Files\Test\test.exe /lang:ENU /vercfg:2.0 /verman:2.0 /prod:lws /version:13.0.1783

    the ::PathRemoveArgs method of CPath class modifies the application path as:

    c:\Program

    Which is not a expected result. we need to seperate out the application path and command line parameters.

    Wednesday, April 13, 2011 8:22 AM
  • Hmm. It seems it's not as clever as I had thought it would be.
     
    The problem is clearly in the space character. Are you not getting the
    path quoted?
     
    If you get it quoted, like
    "c:\Program Files\Test\test.exe" /lang:ENU /vercfg:2.0 /verman:2.0
    /prod:lws /version:13.0.1783
     
    you can do
         path.RemoveArgs();
        path.UnquoteSpaces();
        path.StripPath();
     
    and it works fine.
     
    But if you can't get the path quoted, I think you'll have to make it "by
    hand"
     
    Wednesday, April 13, 2011 8:43 AM
  • It is not possible in our project to provide the quoted application path, because we are hooking the CreateProcess API and get the command line parameter from its parameter lpCommandLine.
    Wednesday, April 13, 2011 8:49 AM
  • Well, I've never hooked the CreateProcess API, but reading the
    documentation, it says:
       The lpApplicationName parameter can be NULL. In that case, the module
      name must be the first white space-delimited token in the
      lpCommandLine string. If you are using a long file name that contains
      a space, use quoted strings to indicate where the file name ends and
      the arguments begin; otherwise, the file name is ambiguous.
     
    So, the path should be quoted, shouldn't it? Otherwise, the caller of
    CreateProcess would be running into problems, I guess.
     
    But anyway, if you are getting an unquoted long path with parameters, I
    think you'll have to try to guess it yourself, but it can be tricky.
     
    If the command line is correct, searching for the first slash ("/")
    after a space could give you the end of the path. But if there is an
    error in the command line, i.e. the first parameter is without
    delimiter, you'll run into trouble. The same if there can be parameters
    without delimiter.
     
    You could also "rebuild" the path from the beginning, copying the
    original string by sections and checking if what you've built is a
    directory, or a file, etc.
     
    But it seems that making it correct and reliable won't be easy.
     
    Wednesday, April 13, 2011 9:13 AM
  • Yes, the problem is there is a long flename containing spaces, which is not properly delimited with quotation marks to separate it from the command-line parameters.  The file path (i.e. arg[0]) could end at any space, and the parameters could start at that space.  But how to determine which space that is?
     
    Try assuming that if a space is part of a valid path, then it is part of the path:  form a path containing the characters up to the first space, then include the characters beyond that space, until the next ‘\’, space, or end of string.  If that path exists on the disk, the space is part of the file path – continue by repeating above, searching for the next space.  If not, stop -- the parameters start at the previous space.
     
    This has worked well for me in the past.  But it is not foolproof because it is possible (though not likely) the user intended the file path to be shorter and for the parameters to start with what we assumed was the file path!
     
    -- David
     
     
    "Mikel Luri" wrote in message news:b26d15ba-231e-4f2a-ae70-57068bf1db60@communitybridge.codeplex.com...
     
    You could also "rebuild" the path from the beginning, copying the
    original string by sections and checking if what you've built is a
    directory, or a file, etc.
     
    But it seems that making it correct and reliable won't be easy.
     
    < /DIV>

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com
    Wednesday, April 13, 2011 2:18 PM
  • CreateProcess ends up calling NtCreateProcess.  You could hook NtCreateProcess and see what path is received by NtCreateProcess (perhaps CreateProcess has already parsed the long filename and you can use the results that are passed to NtCreateProcess).
     
    -- David
     
     
    "anshul.jswl" wrote in message news:9d7b7132-4634-4454-8456-49cefc3abf3a@communitybridge.codeplex.com...
    It is not possible in our project to provide the quoted application path, because we are hooking the CreateProcess API and get the command line parameter from its parameter lpCommandLine.

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com
    Wednesday, April 13, 2011 2:20 PM
  • How are you getting the entire string in the first place?  Windows will usually quote the portion of the command-line that involves the program being executed.  For example, look at how Process Explorer shows the command line of running processes.

    If you are hooking CreateProcess, then you have all the information you need.  Read the documentation for CreateProcess carefully.  It basically tells you how Windows will parse the command line you supply.

    If lpApplicationName is NULL, then there are special rules for how lpCommandLine must be supplied in order to handle ambiguous command-lines where there may be spaces in the path to the application.

    The simple answer is that if an command doesn't start with a quote, then the first whitespace character signifies the end of the application/module.  Otherwise the second quote signifies the end of the application/module and the rest is arguments.


    //Charles Oppermann http://weblogs.asp.net/chuckop
    Wednesday, April 13, 2011 8:40 PM
  • Thursday, April 26, 2012 7:50 AM
  • Hi All,

    I developed code to extract the application name from command line. The below code will give us the desired app name, but this is not a full proff solution. I can say it will be working in 70-80% cases but not 100% solution. Must try :

    BOOL ExtractAppPathNName(CString strCommandLine, CString& strrefAppPath, CString& strrefAppName)
    {
    //---
    BOOL bRet = FALSE;
    BOOL bIsCont = FALSE;
    
    int iTemp = 0;
    int iIndex = 0, iPrevIndex = 0;
    int iIndexTemp = 0;
    int iLastIndex = 0;
    int iCount = 0;
    int iFirst = -1;
    int nCount = -1;
    
    CString strLeft = _T("");
    CString strRight = _T("");
    CString strTemp = _T("");
    CString strTemp1 = _T("");
    
    CString strLocalCmdLine = _T("");
    CString strLocalAppPath = _T("");
    CString strLocalAppName = _T("");
    //---
    
    try
    {
    //Validating input parameters.
    if(strCommandLine && strrefAppPath && strrefAppName)
    {
    strrefAppPath.Empty();
    strrefAppName.Empty();
    
    //Getting local copy of Command Line.
    strLocalCmdLine.Empty();
    strLocalCmdLine = strCommandLine;
    
    //Validating command line parameter.
    if(!strLocalCmdLine.IsEmpty())
    {
    //Removing "(double-quote).
    strLocalCmdLine.Remove(_T('"'));
    
    iIndex = strLocalCmdLine.FindOneOf(_T("/*?\"<>|"));
    if(-1 != iIndex)
    {
    strLocalCmdLine = strLocalCmdLine.Left(iIndex);
    }
    
    iIndex = strLocalCmdLine.Find(_T(":"), 2);
    if(-1 != iIndex)
    {
    strLocalCmdLine = strLocalCmdLine.Left(iIndex);
    }
    
    //Extracting Application Path.
    iIndex = 0;
    bIsCont = TRUE;
    //Continue the loop.
    while(bIsCont)
    {
    if((0 <= iIndex) && (strLocalCmdLine.GetLength() > iIndex))
    {
    iPrevIndex = iIndex;
    //Searching for any occurance of a '.'
    iIndex = strLocalCmdLine.Find(_T('.'), iIndex);
    
    if(-1 != iIndex)
    {
    //Get the sub string on left side of '.'
    iFirst = 0;
    nCount = iIndex;
    strLeft.Empty();
    strLeft = strLocalCmdLine.Mid(iFirst, nCount);
    
    iFirst = nCount;
    
    nCount = strLocalCmdLine.GetLength() - nCount;
    
    strTemp.Empty();
    strTemp = strLocalCmdLine.Right(nCount);
    
    strTemp1.Empty();
    if(1 < strTemp.GetLength())
    strTemp1 = strTemp.Mid(1);
    else
    strTemp1 = strTemp;
    
    iPrevIndex = iIndex;
    iIndex = strTemp1.FindOneOf(_T(".\\ /"));
    if(-1 != iIndex)
    {
    iIndex += 1;
    
    strTemp1.Empty();
    strTemp1 = strTemp.GetAt(iIndex);
    
    iIndex += iFirst;
    
    if((!strTemp1.Compare(_T(" "))) || 
    (!strTemp1.Compare(_T("/"))))
    {
    if(iIndex > iFirst)
    {
    //Get the sub string on right side of '.'
    //Upto the next occurance of a \(backslash) or
    //space or a /(fordwardslash)
    nCount = iIndex-iFirst;
    strRight.Empty();
    strRight = strLocalCmdLine.Mid(iFirst, nCount);
    
    if((0 == strRight.CompareNoCase(_T(".exe"))) ||
      (0 == strRight.CompareNoCase(_T(".msi"))) ||
      (0 == strRight.CompareNoCase(_T(".bat"))))
    {
    bIsCont = FALSE;
    //Discontinue the loop.
    }
    else
    {
    strRight.Empty();
    }
    }
    }
    }
    
    if((!strLeft.IsEmpty()) && (!strRight.IsEmpty()))
    {
    strLocalAppPath.Empty();
    strLocalAppPath = strLeft + strRight;
    }
    }
    else
    {
    if(iPrevIndex)
    {
    strTemp.Empty();
    strTemp = strLocalCmdLine.Mid(iPrevIndex+1);
    //strTemp.TrimLeft();
    //strTemp.TrimRight();
    
    iIndex = strTemp.FindOneOf(_T("\\ /"));
    if(-1 != iIndex)
    {
    strTemp1.Empty();
    strTemp1 = strTemp.GetAt(iIndex);
    
    iIndex += 1;
    iIndex += iPrevIndex;
    iPrevIndex = iIndex;
    
    if((!strTemp1.Compare(_T(" "))) || 
    (!strTemp1.Compare(_T("/"))))
    iIndex = -1;
    }
    else
    {
    iPrevIndex = strLocalCmdLine.GetLength();
    iIndex = -1;
    }
    }
    else
    {
    iPrevIndex = strLocalCmdLine.GetLength();
    iIndex = -1;
    }
    }
    }
    else
    {
    if(iPrevIndex)
    {
    iIndex = strLocalCmdLine.Find(_T(':'), iPrevIndex);
    if(-1 != iIndex)
    {
    nCount = iIndex-1;
    strLocalAppPath.Empty();
    strLocalAppPath = strLocalCmdLine.Left(nCount);
    }
    else
    {
    iIndex = strLocalCmdLine.Find(_T(' '), iPrevIndex);
    if(-1 != iIndex)
    {
    nCount = iIndex;
    }
    else
    {
    nCount = strLocalCmdLine.GetLength();
    }
    
    if(0 <= nCount)
    strLocalAppPath = strLocalCmdLine.Left(nCount);
    }
    }
    else
    strLocalAppPath = strLocalCmdLine;
    
    //Discontinue the loop.
    bIsCont = FALSE;
    }
    }
    
    //Checking for application name in application path.
    if(!strLocalAppPath.IsEmpty())
    {
    iIndex = strLocalAppPath.ReverseFind(_T('\\'));
    if(-1 != iIndex)
    {
    iLastIndex = strLocalAppPath.GetLength();
    
    if(iLastIndex > iIndex)
    iCount  = iLastIndex - iIndex -1;
    
    iIndex += 1;
    }
    else
    {
    iIndex = 0;
    iCount = strLocalAppPath.GetLength();
    }
    
    if(0 > iCount)
    iCount = 0;
    
    strLocalAppPath.TrimLeft();
    strLocalAppPath.TrimRight();
    
    //Extracting for application name in application path.
    strLocalAppName.Empty();
    strLocalAppName = strLocalAppPath.Mid(iIndex, iCount);
    
    strLocalAppName.TrimLeft();
    strLocalAppName.TrimRight();
    
    //Assigning result to out parameters.
    strrefAppPath.Empty();
    strrefAppPath = strLocalAppPath;
    
    strrefAppName.Empty();
    strrefAppName = strLocalAppName;
    
    //Success.
    bRet = TRUE;
    } 
    }
    }
    }
    catch(...)
    {
    }
    
    return bRet;
    }




    • Marked as answer by Anshul Jaiswal Wednesday, October 10, 2012 1:46 PM
    • Edited by Anshul Jaiswal Wednesday, October 10, 2012 7:03 PM correction
    Wednesday, October 10, 2012 1:26 PM
  • anshul.jswl wrote:

    I developed code to extract the application name from command line.

    Any reason you can't just call GetModuleFileName(NULL) ?


    Igor Tandetnik

    • Marked as answer by Anshul Jaiswal Wednesday, October 10, 2012 1:46 PM
    • Unmarked as answer by Anshul Jaiswal Wednesday, October 10, 2012 1:46 PM
    Wednesday, October 10, 2012 1:28 PM
  • As I do not want  the application name of current module, in my application I am receiving the command line parameters for running apps by some other way, hence GetModuleFileName does not works for me.

    I am considering the case where we need to extract the app name for command line received for running apps by hooking the CreateProcess API. Like this there may be several other cases where we need to resolve apps command line. In that case the above code may help, as this code helps me out.


    Wednesday, October 10, 2012 1:37 PM