/* (C) 2003 XDA Developers * Author: Willem Jan Hengeveld * Web: http://www.xda-developers.com/ * * $Header$ */ #include #include #include using namespace std; #include "debug.h" #include "stringutils.h" bool FindApp(const TCHAR *szProcName, DWORD& dwProcessId) { HANDLE hTH= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); bool bRes= false; PROCESSENTRY32 pe; pe.dwSize= sizeof(PROCESSENTRY32); if (Process32First(hTH, &pe)) { do { if (wcsicmp(szProcName, pe.szExeFile)==0) { bRes= true; dwProcessId= pe.th32ProcessID; break; } } while (Process32Next(hTH, &pe)); } CloseToolhelp32Snapshot(hTH); return bRes; } bool AppExists(const string &processname) { wstring wprocname= ToWString(processname); DWORD dwProcessId; return FindApp(wprocname.c_str(), dwProcessId); } bool KillApp(const string &processname) { wstring wprocname= ToWString(processname); DWORD dwProcessId; if (!FindApp(wprocname.c_str(), dwProcessId)) return false; bool bRes= false; HANDLE hProc= OpenProcess(0, 0, dwProcessId); if (TerminateProcess(hProc, 0)) bRes= true; CloseHandle(hProc); return bRes; } bool RunApp(const string &appname, const string &commandline) { wstring wappname= ToWString(appname); wstring wcmdline= ToWString(commandline); SHELLEXECUTEINFO exec; memset(&exec, 0, sizeof(SHELLEXECUTEINFO)); exec.cbSize= sizeof(SHELLEXECUTEINFO); exec.lpFile= wappname.c_str(); exec.lpParameters= wcmdline.c_str(); exec.lpVerb= L"open"; exec.nShow= SW_SHOW; exec.fMask= SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS; if (!ShellExecuteEx(&exec)) { error("shellexecute"); return false; } return true; } /* --- alternative ways to run programs: //CreateProcess(L"\\Windows\\XDA Unlock.exe", L"-q", NULL, NULL, false, 0, NULL, NULL, NULL, NULL); //ShellExecute(0, L"open", L"\\Windows\\XDA Unlock.exe", L"-q", NULL, SW_SHOW); SYSTEMTIME systime; GetLocalTime(&systime); TIME_ZONE_INFORMATION tz; GetTimeZoneInformation(&tz); SYSTEMTIME runtime; GetNextRunTime(&tz, &systime, 0, &runtime); // not sure about 3rd parameter CeRunAppAtTime(L"\\Windows\\XDAUnlock.lnk", &runtime); // must use link, with exe + parameter in .lnk file */