[Bug 8549] ITaskScheduler not supported
http://bugs.winehq.org/show_bug.cgi?id=8549 --- Comment #9 from frog <frog-bz(a)inwa.net> 2008-10-30 11:22:28 --- // lsTasks lists scheduled jobs for a Windows 2000 or later machine. // Written 26-dec-2002 by frank brown // // Mod 16-dec-2003 by fgb: call getflags to report if task is disabled // (version 1.1). // // List format: // ----------- // jobname: command // // ITaskScheduler::Enum #define TASKS_TO_RETRIEVE 5 #define UNICODE #define _UNICODE #define _WIN32_DCOM #include <windows.h> #include <initguid.h> #include <ole2.h> #include <mstask.h> #include <msterr.h> #include <objidl.h> #include <wchar.h> #include <wtypes.h> #include <stdio.h> // globals: const wchar_t szAppName[] = L"lsTasks"; const wchar_t szCopyright[] = L"Copyright 2002-2003 by Bamboo Software"; wchar_t szMachine[64]; WORD wStartHh = 0,wStartMm = 0; wchar_t gszStartTime[32]; wchar_t szTmp[256]; const wchar_t szVersion[] = L"1.1"; // protos: void ComErrExit(LPCWSTR pszStr,HRESULT hr); void ExtractArg(LPWSTR pszArg,LPWSTR pszVar); void Help(); // let's go: void ComErrExit(LPCWSTR pszStr,HRESULT hr) { const int W_CANTCONFIRMACCOUNT = 0x80041310; const int W_CANTFINDMACHINE = 0x80070035; swprintf(szTmp,L"%s error 0x%x: ",pszStr,hr); switch (hr) { case E_ACCESSDENIED: case E_OUTOFMEMORY: wcscat(szTmp,L"Access denied"); break; case E_INVALIDARG: wcscat(szTmp,L"One or more args invalid"); break; case E_NOINTERFACE: wcscat(szTmp,L"Specified interface not available"); break; case CO_S_NOTALLINTERFACES: wcscat(szTmp,L"Not all interfaces available"); break; case REGDB_E_CLASSNOTREG: wcscat(szTmp,L"Class not registered"); break; case HRESULT_FROM_WIN32 (ERROR_FILE_EXISTS): wcscat(szTmp,L"Task exists"); break; case W_CANTCONFIRMACCOUNT: swprintf(szTmp,L"%s warning 0x%x: ",pszStr,hr); wcscat(szTmp,L"Can't confirm account exists"); break; case W_CANTFINDMACHINE: swprintf(szTmp,L"Can't find machine %s",szMachine); break; default: wcscat(szTmp,L"Unknown error"); } _putws(szTmp); CoUninitialize(); ExitProcess(1); } void ExtractArg(LPWSTR pszArg,LPWSTR pszVar) { wchar_t *pch; pch = wcschr(pszArg,L'='); if (!pch) { Help(); ExitProcess(1); } do { ++pch; } while (*pch == L' '); wcscpy(pszVar,pch); } void Help() { wprintf(L"\n%s %s %s\n\n",szAppName,szVersion,szCopyright); wprintf(L"List scheduled tasks for a computer.\n\n"); wprintf(L"usage: %s [machine] \n\n",szAppName); } void main(int argc, char **argv) { int argcw; wchar_t **argvw,*pch; bool bDisabled = false; HRESULT hr = ERROR_SUCCESS; ITaskScheduler *pITS; wchar_t szLine[512]; wchar_t szPwd[32]; bool bSyStartup = false; wchar_t szTaskApp[256] = L""; wchar_t szTaskName[64] = L"unknown"; IUnknown *pUnknown = NULL; wchar_t szUser[128]; // Initializations: DWORD dwLen = 64; wchar_t szJunk[64]; if (!GetComputerName(szJunk,&dwLen)) _putws(L"It's a strange world where we can't get the computer name."); else wsprintf(szMachine,L"\\\\%s",szJunk); // Handle commandline: //if (argc < 2) { Help(); ExitProcess(0); } argvw = CommandLineToArgvW(GetCommandLine(),&argcw); if (argc > 1) { if (argvw[1][0] == L'\\') wcscpy(szMachine,argvw[1]); else wsprintf(szMachine,L"\\\\%s",argvw[1]); } for (int i=1; i<argcw; i++) { if (argvw[i][0] == L'/' || argvw[i][0] == L'-') switch(towlower(argvw[i][1])) { case L'?': case L'h': Help(); ExitProcess(0); break; } } ///////////////////////////////////////////////////////////////// // Call CoInitialize to initialize the COM library and then // CoCreateInstance to get the Task Scheduler object: ///////////////////////////////////////////////////////////////// hr = CoInitialize(0); if (FAILED(hr)) { CoUninitialize(); ExitProcess(1); } hr = CoCreateInstance(CLSID_CTaskScheduler, NULL, CLSCTX_SERVER, IID_ITaskScheduler, (void **) &pITS); // Select [remote] computer: hr = pITS->SetTargetComputer(szMachine); if (FAILED(hr)) ComErrExit(L"SetTargetComputer",hr); else wprintf(L"Scheduled jobs on %s:\n\n",szMachine); // LPCWSTR pwszTaskName = szTaskName; ///////////////////////////////////////////////////////////////// // Call ITaskScheduler::Enum to get an enumeration object. ///////////////////////////////////////////////////////////////// IEnumWorkItems *pIEnum; hr = pITS->Enum(&pIEnum); if (FAILED(hr)) ComErrExit(L"EnumWorkItems",hr); ///////////////////////////////////////////////////////////////// // Call IEnumWorkItems::Next to retrieve tasks. Note that // this example tries to retrieve five tasks for each call. ///////////////////////////////////////////////////////////////// LPWSTR *lpwszNames; DWORD dwFetchedTasks = 0; while (SUCCEEDED(pIEnum->Next(TASKS_TO_RETRIEVE, &lpwszNames, &dwFetchedTasks)) && (dwFetchedTasks != 0)) { /////////////////////////////////////////////////////////////////// // Process each task. This involves: (1) calling Activate to get // the task object; (2) getting the app name; (3) printing the info. /////////////////////////////////////////////////////////////////// for (DWORD i=0; i<dwFetchedTasks; i++) { /////////////////////////////////////////////////////////////////// // Call ITaskScheduler::Activate to get the task object. /////////////////////////////////////////////////////////////////// ITask *pITask; LPCWSTR lpcwszTaskName; lpcwszTaskName = lpwszNames[i]; hr = pITS->Activate(lpcwszTaskName,IID_ITask,(IUnknown**)&pITask); if (FAILED(hr)) ComErrExit(L"ITaskScheduler::Activate",hr); // Now get info about the job: LPWSTR lpwszAppName; hr = pITask->GetApplicationName(&lpwszAppName); if (FAILED(hr)) ComErrExit(L"ITask::GetApplicationName",hr); LPWSTR lpwszParams; hr = pITask->GetParameters(&lpwszParams); if (FAILED(hr)) ComErrExit(L"ITask::GetParameters",hr); DWORD dwFlags; hr = pITask->GetFlags(&dwFlags); if (FAILED(hr)) ComErrExit(L"ITask::GetFlags",hr); bDisabled = (TASK_FLAG_DISABLED & dwFlags)? true : false; pITask->Release(); wsprintf(szLine,L"%s: %s %s",lpcwszTaskName,lpwszAppName,lpwszParams); if (bDisabled) wcscat(szLine,L" -disabled"); wcscat(szLine,L"\n"); wprintf(szLine); CoTaskMemFree(lpwszAppName); CoTaskMemFree(lpwszParams); CoTaskMemFree(lpwszNames[i]); } CoTaskMemFree(lpwszNames); } pITS->Release(); CoUninitialize(); // ExitProcess(0); } -- Configure bugmail: http://bugs.winehq.org/userprefs.cgi?tab=email Do not reply to this email, post in Bugzilla using the above URL to reply. ------- You are receiving this mail because: ------- You are watching all bug changes.
participants (1)
-
wine-bugs@winehq.org