Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
Delphi 12 Athens
|
Re: Prozess Starten
5. Mai 2008, 18: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;
}
$2B or not $2B
|
|
Zitat
|