Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.200 Beiträge
 
Delphi 12 Athens
 
#17

Re: Prozess Starten

  Alt 5. Mai 2008, 17:55
hab da grad was in der ShellAPI.h gefunden ... sieht doch nett aus?
Code:
HRESULT MyShellExec(PCWSTR pszCmd)
{
    PWSTR pszApp;
    PWSTR pszCmdLine;
    HRESULT hr = SHEvaluateSystemCommandTemplate(pszCmd, &pszApp, &pszCmdLine);
    if (SUCCEEDED(hr))
    {
        //  if this was a real template, maybe some kind of wnsprintf() first?
        SHELLEXECUTEINFOW sei = {
            sizeof(sei),          // cbSize;
            0,                    // fMask
            NULL,                 // hwnd
            NULL,                 // lpVerb
            pszApp,               // lpFile
            PathGetArgs(pszCmdLine), // lpParameters
            NULL,                 // lpDirectory
            SW_SHOWNORMAL,        // nShow
            0,                    // hInstApp
            NULL,                 // lpIDList
            NULL,                 // lpClass
            NULL,                 // hkeyClass
            0,                    // dwHotKey
            NULL,                 // hIcon
            NULL                  // hProcess
        };

        if (ShellExecuteEx(&sei))
        {
            //  we are good
            ASSERT(hr == S_OK);
        }
        else
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }

        CoTaskMemFree(pszApp);
        CoTaskMemFree(pszCmdLine);
    }
    return hr;
}

HRESULT MyCreateProcessPriv(PCWSTR pszCmd)
{
    PWSTR pszApp;
    PWSTR pszCmdLine;
    HRESULT hr = SHEvaluateSystemCommandTemplate(pszCmd, &pszApp, &pszCmdLine);
    if (SUCCEEDED(hr))
    {
        //  if this was a real template, maybe some kind of wnsprintf() first?
        PROCESS_INFORMATION pi;
        STARTUPINFO si = {0};
        si.cb = sizeof(startup);
        si.wShowWindow = SW_SHOWNORMAL;

        if (CreateProcess(pszApp, pszCmdLine, NULL, NULL, FALSE,
                 CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi))
        {
            //  we are good
            ASSERT(hr == S_OK);
            CloseHandle(pi.hProcess);
            CloseHandle(pi.hThread);
        }
        else
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }

        CoTaskMemFree(pszApp);
        CoTaskMemFree(pszCmdLine);
    }
    return hr;
}
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat