def BuildCommand(pExpandFile, pKey, pExtension, pArgs, pVerbose=False):
    '''
    The extension from pExpandFile is used to select the command associated with
    the command named in pKey for the file type associated with the given extension.

    pExpandFile - File to be processed
    pKey        - Command name
    pExtension  - Extension used to select command text
    pArgs       - Passed arguments

    Note: c:\messagebox.exe displays its command line in a popup window.
    '''
    if pVerbose:      # not currently used for anything
        lValues = GetExtensionInfo(pExtension)
    else:
        lValues = {}
    if len(pArgs) > 1:
        pArgs = pArgs[1:]
    else:
        pArgs = []
    lExpandFile = pExpandFile
    lKey = pKey
    lAbort = False
    
    lText = ''
    if len(lKey) > 0 and len(lExpandFile) > 0:
        lPos = lExpandFile.rfind('.')
        if lPos > 0:
            if pExtension == '':
                lExtension = lExpandFile[lPos:]
            else:
                lExtension = pExtension
            lFileType = QueryValue(HKEY_CLASSES_ROOT, lExtension)
            if len(lFileType) > 0:
                (lAbort, lText) = GetCommand(lFileType, lKey)
                if lAbort:
                    (lAbort, lText) = GetCommand('*', lKey)
            else:
                lAbort = True
                pass
        else:
            lAbort = True
            pass
    else:
        lAbort = True
        pass
        
    lArgs = ''
    if len(pArgs) > 0:
        lArgs = ' '.join(pArgs)
    if not lAbort:
        if lText.find("%") >= 0:
            lText = lText.replace("%1", str(lExpandFile))
            for lCount in range(0,len(pArgs)):
                lString = '%' + str(lCount+2)
                lText = lText.replace(lString, pArgs[lCount])
                lText = lText.replace("%*", lArgs)
        else:
            lText += " " + lExpandFile + " "+ lArgs
            
        if lText.find('{') >= 0:
            lText = Do.Expand(lText, lExpandFile)

    else:
        lText = ''
    return lText

    The extension from pExpandFile is used to select the command associated with
    the command named in pKey for the file type associated with the given extension.

    pExpandFile - File to be processed
    pKey        - Command name
    pExtension  - Extension used to select command text
    pArgs       - Passed arguments

    Note: c:\messagebox.exe displays its command line in a popup window.
    
recipes/Python/577441_Run_command_in_Win32_Registry/recipe-577441.py