Esempio n. 1
0
//************************************
// Method:    ReadInAutoStartAppsFromStartupFolder
// FullName:  CAutoStartupInfo::ReadInAutoStartAppsFromStartupFolder
// Access:    private
// Returns:   bool
// Qualifier:
//************************************
bool CAutoStartupInfo::FindExeFromPath( CString csPath_i )
{
    // Prepare wild card string for fetching all files from the startup folder
    csPath_i += _T( "*.*" );

    // Helper for finding files
    CFileFind cfFileFinder;
    BOOL bFound = cfFileFinder.FindFile( csPath_i );

    // Keep searching
    while( bFound )
    {
        bFound = cfFileFinder.FindNextFile();

        // Skip dots and directories
        if( cfFileFinder.IsDots() ||
                cfFileFinder.IsDirectory() )
        {
            continue;
        }

        CString csFilePath = cfFileFinder.GetFilePath();
        if( !PathIsExe( csFilePath ))
        {
            if( Utils::IsShortcut( csFilePath ))
            {
                LPTSTR lptszPath = csFilePath.GetBufferSetLength( MAX_PATH );

                // Resolve path
                const BOOL bIsResolved = Utils::ResolveShortcut( lptszPath );
                csFilePath.ReleaseBuffer();
                if( !bIsResolved )
                {
                    continue;
                }
            }// End if
        }// End if

        // Found a valid exe, store it in our collection
        AddAutoStartExePath( csFilePath );
    }// End while

    return true;
}// End FindExeFromPath
Esempio n. 2
0
/** 
 * 
 * Static helper that returns type of process.
 * 
 * @param       lpctszProcessPath_i - Process path.
 * @return      PROCESS_TYPE_e      - Return type of process
 * @exception   Nil
 * @see         Nil
 * @since       1.0
 */
PROCESS_TYPE_e Process::ExtractProcessType( LPCTSTR lpctszProcessPath_i, CString* pcsProcessType_o )
{
    // Check parameter
    if( !lpctszProcessPath_i ||             // Should not be null
        !lpctszProcessPath_i[0] ||          // Should not be empty
        !PathIsExe( lpctszProcessPath_i ))  // Should be an executable file
    {
        return PRT_INVALID;
    }


    // Second call is for retrieving file type
    const DWORD dwRetVal = SHGetFileInfo( lpctszProcessPath_i, 
                                          FILE_ATTRIBUTE_NORMAL, 
                                          0, 
                                          0, 
                                          SHGFI_EXETYPE );
    // Check return value from API 
    if( !dwRetVal )
    {
        // Some error
        return PRT_INVALID;
    }

    
   /************************************************************************
       dwRetVal is interpreted as follows...
       LOWORD = NE or PE and HIWORD = 3.0, 3.5, or 4.0  Windows application 
       LOWORD = MZ and HIWORD = 0  MS-DOS .exe, .com, or .bat file 
       LOWORD = PE and HIWORD = 0  Win32 console application 
    ************************************************************************/

    const WORD wLowWord =  LOWORD( dwRetVal );
    const WORD wHiWord = HIWORD( dwRetVal );
    const WORD wPEWord = MAKEWORD( 'P', 'E' );
    const WORD wMZWord = MAKEWORD( 'M', 'Z' );
    const WORD wNEWord = MAKEWORD( 'N', 'E' );

    // Read above comments to understand what's happening
    if( wLowWord == wPEWord || wLowWord == wNEWord )
    {
        if( wHiWord == 0 )
        {
            if( pcsProcessType_o )
            {
                *pcsProcessType_o = _T( "Win32 Console application" );
            }

            // Console process
            return PRT_WIN32_CONSOLE;
        }
        else
        {
            if( *pcsProcessType_o )
            {
                *pcsProcessType_o = _T( "Win32 Windows application" );
            }

            // Windows process
            return PRT_WIN32_WINDOWS;
        }// End if
    }
    else if( wLowWord == wMZWord && wHiWord == 0 )
    {
        if( *pcsProcessType_o )
        {
            *pcsProcessType_o = _T( "MS-DOS application" );
        }

        // MS-DOS process
        return PRT_MSDOS;
    }// End if

    // We are here because type is invalid
    return PRT_INVALID;
}// End GetProcessType