示例#1
0
void StartupRunner::_RunShellFolderContents(int nFolder)
{
    TCHAR tzPath[MAX_PATH] = { 0 };
    
    if (GetShellFolderPath(nFolder, tzPath, COUNTOF(tzPath)))
    {
        if (tzPath[0])
        {
            TCHAR tzSearchPath[MAX_PATH] = { 0 };
            PathCombine(tzSearchPath, tzPath, _T("*.*"));
            
            WIN32_FIND_DATA findData = { 0 };
            HANDLE hSearch = FindFirstFile(tzSearchPath, &findData);
            
            while (hSearch != INVALID_HANDLE_VALUE)
            {
                if (!PathIsDirectory(findData.cFileName) &&
                    !(findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) &&
                    !(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
                {
                    SHELLEXECUTEINFO seiCommand = { 0 };
                    
                    seiCommand.cbSize = sizeof(SHELLEXECUTEINFO);
                    seiCommand.lpFile = findData.cFileName;
                    seiCommand.lpDirectory = tzPath;
                    seiCommand.nShow = SW_SHOWNORMAL;
                    seiCommand.fMask =
                        SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI;
                    
                    if (!LSShellExecuteEx(&seiCommand))
                    {
                        TRACE("StartupRunner failed to launch '%s'",
                            findData.cFileName);
                    }
                }
                
                if (!FindNextFile(hSearch, &findData))
                {
                    FindClose(hSearch);
                    hSearch = INVALID_HANDLE_VALUE;
                }
            }
        }
    }
    else
    {
        TRACE("Failed to get full path to Startup folder %d", nFolder);
    }
}
示例#2
0
//
// LSExecuteEx
//
HINSTANCE LSExecuteEx(HWND hOwner, LPCSTR pszOperation, LPCSTR pszCommand, LPCSTR pszArgs, LPCSTR pszDirectory, int nShowCmd)
{
    HINSTANCE hReturn = HINSTANCE(32);
    
    if (pszCommand != NULL)
    {
        if (pszCommand[0] == '!')
        {
            hReturn = ParseBangCommand(hOwner, pszCommand, pszArgs) ?
                HINSTANCE(33) : HINSTANCE(32);
        }
        else
        {
            TRACE("LSExecuteEx(%.8X, \"%s\", \"%s\", \"%s\", \"%s\", %d);",
                hOwner, pszOperation, pszCommand, pszArgs,pszDirectory,
                nShowCmd);
            
            if (PathIsDirectory(pszCommand))
            {
                hReturn = LSShellExecute(hOwner, pszOperation, pszCommand,
                    pszArgs, NULL, nShowCmd ? nShowCmd : SW_SHOWNORMAL);
            }
            else
            {
                SHELLEXECUTEINFO seiCommand = { 0 };
                seiCommand.cbSize = sizeof(SHELLEXECUTEINFO);
                seiCommand.hwnd = hOwner;
                seiCommand.lpVerb = pszOperation;
                seiCommand.lpFile = pszCommand;
                seiCommand.lpParameters = pszArgs;
                seiCommand.lpDirectory = pszDirectory;
                seiCommand.nShow = nShowCmd;
                seiCommand.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI;
                
                LSShellExecuteEx(&seiCommand);
                
                hReturn = seiCommand.hInstApp;
            }
        }
    }
    
    return hReturn;
}
示例#3
0
HANDLE StartupRunner::_ShellExecuteEx(LPCTSTR ptzExecutable, LPCTSTR ptzArgs)
{
    HANDLE hReturn = NULL;
    
    SHELLEXECUTEINFO sei = { 0 };
    sei.cbSize = sizeof(sei);
    sei.lpFile = ptzExecutable;
    sei.lpParameters = ptzArgs;
    sei.nShow = SW_SHOWNORMAL;
    sei.fMask = \
        SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
    
    if (LSShellExecuteEx(&sei))
    {
        hReturn = sei.hProcess;
    }
    
    return hReturn;
}
示例#4
0
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// StartExplorerShell
// Try to start Explorer in shell mode
//
bool StartExplorerShell(DWORD dwWaitTimeout)
{
    bool bStarted = false;
    TCHAR szOldShell[MAX_PATH] = { 0 };

    DWORD dwCopied = GetPrivateProfileString(_T("boot"), _T("shell"), NULL,
        szOldShell, COUNTOF(szOldShell), _T("system.ini"));

    // If this user account has limited access rights and
    // the shell is in HKLM, GetPrivateProfileString returns 0
    if (dwCopied > 0 && dwCopied < (COUNTOF(szOldShell)-1))
    {
        if (WritePrivateProfileString(
            _T("boot"), _T("shell"), _T("explorer.exe"), _T("system.ini")))
        {
            // We have successfully set Explorer as shell, now launch it...
            SHELLEXECUTEINFO sei = { 0 };
            sei.cbSize = sizeof(sei);
            sei.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS;
            sei.lpVerb = _T("open");
            sei.lpFile = _T("%windir%\\explorer.exe");

            if (LSShellExecuteEx(&sei))
            {
                // If we don't wait here, there'll be a race condition:
                // We may reset the 'shell' setting before Explorer reads it.
                if (WaitForInputIdle(sei.hProcess, dwWaitTimeout) == 0)
                {
                    bStarted = true;
                }

                CloseHandle(sei.hProcess);
            }

            WritePrivateProfileString(
                _T("boot"), _T("shell"), szOldShell, _T("system.ini"));
        }
    }

    return bStarted;
}