Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1388 lines
32 KiB

  1. /******************************************************************************
  2. Copyright(c) Microsoft Corporation
  3. Module Name:
  4. QueryTasks.cpp
  5. Abstract:
  6. This module queries the different properties of a Scheduled Task
  7. Author:
  8. G.Surender Reddy 10-Sept-2000
  9. Revision History:
  10. G.Surender Reddy 10-Sep-2000 : Created it
  11. G.Surender Reddy 25-Sep-2000 : Modified it
  12. [ Made changes to avoid memory leaks,
  13. changed to suit localization ]
  14. G.Surender Reddy 15-oct-2000 : Modified it
  15. [ Moved the strings to Resource table ]
  16. ******************************************************************************/
  17. //common header files needed for this file
  18. #include "pch.h"
  19. #include "CommonHeaderFiles.h"
  20. /******************************************************************************
  21. Routine Description:
  22. This function returns the next or last run time of the task depending on
  23. the type of time specified by user.
  24. Arguments:
  25. [ in ] pITask : Pointer to the ITask interface
  26. [ out ] pszRunTime : pointer to the string containing Task run time[last or next]
  27. [ out ] pszRunDate : pointer to the string containing Task run Date[last or next]
  28. [ in ] dwTimetype : Type of run time[TASK_LAST_RUNTIME or TASK_NEXT_RUNTIME]
  29. Return Value:
  30. A HRESULT value indicating S_OK on success else S_FALSE on failure
  31. ******************************************************************************/
  32. HRESULT
  33. GetTaskRunTime(ITask* pITask,_TCHAR* pszRunTime,_TCHAR* pszRunDate,DWORD dwTimetype,
  34. WORD wTriggerNum)
  35. {
  36. HRESULT hr = S_OK;
  37. SYSTEMTIME tRunTime = {0,0,0,0,0,0,0,0};
  38. _TCHAR szTime[MAX_DATETIME_LEN] = NULL_STRING;
  39. _TCHAR szDate[MAX_DATETIME_LEN] = NULL_STRING;
  40. int iBuffSize = 0;
  41. BOOL bNoStartTime = FALSE;
  42. BOOL bLocaleChanged = FALSE;
  43. LCID lcid;
  44. if(pITask == NULL)
  45. {
  46. return S_FALSE;
  47. }
  48. ITaskTrigger *pITaskTrigger = NULL;
  49. if( ( dwTimetype == TASK_NEXT_RUNTIME ) || ( dwTimetype == TASK_START_RUNTIME ) )
  50. {
  51. //determine the task type
  52. hr = pITask->GetTrigger(wTriggerNum,&pITaskTrigger);
  53. if ( FAILED(hr) )
  54. {
  55. if(pITaskTrigger)
  56. {
  57. pITaskTrigger->Release();
  58. }
  59. return hr;
  60. }
  61. TASK_TRIGGER Trigger;
  62. ZeroMemory(&Trigger, sizeof (TASK_TRIGGER));
  63. hr = pITaskTrigger->GetTrigger(&Trigger);
  64. if ( FAILED(hr) )
  65. {
  66. if( pITaskTrigger )
  67. {
  68. pITaskTrigger->Release();
  69. }
  70. return hr;
  71. }
  72. if( dwTimetype == TASK_START_RUNTIME )
  73. {
  74. tRunTime.wDay = Trigger.wBeginDay;
  75. tRunTime.wMonth = Trigger.wBeginMonth;
  76. tRunTime.wYear = Trigger.wBeginYear;
  77. tRunTime.wHour = Trigger.wStartHour;
  78. tRunTime.wMinute = Trigger.wStartMinute;
  79. }
  80. if((Trigger.TriggerType >= TASK_EVENT_TRIGGER_ON_IDLE) &&
  81. (Trigger.TriggerType <= TASK_EVENT_TRIGGER_AT_LOGON))
  82. {
  83. switch(Trigger.TriggerType )
  84. {
  85. case TASK_EVENT_TRIGGER_ON_IDLE ://On Idle time
  86. LoadResString(IDS_TASK_IDLE , pszRunTime ,
  87. MAX_DATETIME_LEN );
  88. break;
  89. case TASK_EVENT_TRIGGER_AT_SYSTEMSTART://At system start
  90. LoadResString(IDS_TASK_SYSSTART , pszRunTime ,
  91. MAX_DATETIME_LEN );
  92. break;
  93. case TASK_EVENT_TRIGGER_AT_LOGON ://At logon time
  94. LoadResString(IDS_TASK_LOGON , pszRunTime ,
  95. MAX_DATETIME_LEN );
  96. break;
  97. default:
  98. break;
  99. }
  100. if( dwTimetype == TASK_START_RUNTIME )
  101. {
  102. bNoStartTime = TRUE;
  103. }
  104. if( dwTimetype == TASK_NEXT_RUNTIME )
  105. {
  106. lstrcpy( pszRunDate,pszRunTime );
  107. if( pITaskTrigger )
  108. {
  109. pITaskTrigger->Release();
  110. }
  111. return S_OK;
  112. }
  113. }
  114. if( dwTimetype == TASK_NEXT_RUNTIME )
  115. {
  116. hr = pITask->GetNextRunTime(&tRunTime);
  117. if (FAILED(hr))
  118. {
  119. if( pITaskTrigger )
  120. {
  121. pITaskTrigger->Release();
  122. }
  123. return hr;
  124. }
  125. // check whether the task has next run time to run or not..
  126. // If not, Next Run Time would be "Never".
  127. if ( tRunTime.wHour == 0 && tRunTime.wMinute == 0 &&
  128. tRunTime.wDay == 0 && tRunTime.wMonth == 0 && tRunTime.wYear == 0 )
  129. {
  130. LoadResString(IDS_TASK_NEVER , pszRunTime , MAX_DATETIME_LEN );
  131. lstrcpy( pszRunDate,pszRunTime );
  132. if( pITaskTrigger )
  133. {
  134. pITaskTrigger->Release();
  135. }
  136. return S_OK;
  137. }
  138. }
  139. if( pITaskTrigger )
  140. {
  141. pITaskTrigger->Release();
  142. }
  143. }
  144. //Determine Task last run time
  145. else if(dwTimetype == TASK_LAST_RUNTIME )
  146. {
  147. // Retrieve task's last run time
  148. hr = pITask->GetMostRecentRunTime(&tRunTime);
  149. if (FAILED(hr))
  150. {
  151. return hr;
  152. }
  153. }
  154. else
  155. {
  156. return S_FALSE;
  157. }
  158. if((hr == SCHED_S_TASK_HAS_NOT_RUN) && (dwTimetype == TASK_LAST_RUNTIME))
  159. {
  160. LoadResString(IDS_TASK_NEVER , pszRunTime , MAX_DATETIME_LEN );
  161. lstrcpy( pszRunDate,pszRunTime );
  162. return S_OK;
  163. }
  164. // verify whether console supports the current locale fully or not
  165. lcid = GetSupportedUserLocale( bLocaleChanged );
  166. //Retrieve the Date
  167. iBuffSize = GetDateFormat( lcid, 0, &tRunTime,
  168. (( bLocaleChanged == TRUE ) ? L"MM/dd/yyyy" : NULL), szDate, SIZE_OF_ARRAY( szDate ) );
  169. if(iBuffSize == 0)
  170. {
  171. return S_FALSE;
  172. }
  173. // to give the time string format as hh:mm:ss
  174. //_TCHAR szFormat[MAX_TIME_FORMAT_LEN] = NULL_STRING;
  175. //lstrcpy(szFormat , GetResString(IDS_TIME_FORMAT) );
  176. if(!bNoStartTime )
  177. {
  178. iBuffSize = GetTimeFormat( lcid, TIME_FORCE24HOURFORMAT,
  179. &tRunTime, L"HH:mm:ss",szTime, SIZE_OF_ARRAY( szTime ) );
  180. if(iBuffSize == 0)
  181. {
  182. return S_FALSE;
  183. }
  184. }
  185. if( lstrlen(szTime) )
  186. {
  187. lstrcpy(pszRunTime,szTime);
  188. }
  189. if( lstrlen(szDate) )
  190. {
  191. lstrcpy(pszRunDate,szDate);
  192. }
  193. return S_OK;
  194. }
  195. /******************************************************************************
  196. Routine Description:
  197. This function returns the status code description of a particular task.
  198. Arguments:
  199. [ in ] pITask : Pointer to the ITask interface
  200. [ out ] pszStatusCode : pointer to the Task's status string
  201. Return Value:
  202. A HRESULT value indicating S_OK on success else S_FALSE on failure
  203. ******************************************************************************/
  204. HRESULT
  205. GetStatusCode(ITask* pITask,_TCHAR* pszStatusCode)
  206. {
  207. HRESULT hrStatusCode = S_OK;
  208. HRESULT hr = S_OK;
  209. DWORD dwExitCode = 0;
  210. hr = pITask->GetStatus(&hrStatusCode);//Got status of the task
  211. if (FAILED(hr))
  212. {
  213. return hr;
  214. }
  215. *pszStatusCode = NULL_CHAR;
  216. switch(hrStatusCode)
  217. {
  218. case SCHED_S_TASK_READY:
  219. hr = pITask->GetExitCode(&dwExitCode);
  220. if (FAILED(hr))
  221. {
  222. LoadResString(IDS_STATUS_COULDNOTSTART , pszStatusCode , MAX_STRING_LENGTH );
  223. }
  224. else
  225. {
  226. LoadResString(IDS_STATUS_READY , pszStatusCode , MAX_STRING_LENGTH );
  227. }
  228. break;
  229. case SCHED_S_TASK_RUNNING:
  230. LoadResString(IDS_STATUS_RUNNING , pszStatusCode , MAX_STRING_LENGTH );
  231. break;
  232. case SCHED_S_TASK_NOT_SCHEDULED:
  233. hr = pITask->GetExitCode(&dwExitCode);
  234. if (FAILED(hr))
  235. {
  236. LoadResString(IDS_STATUS_COULDNOTSTART , pszStatusCode , MAX_STRING_LENGTH );
  237. }
  238. else
  239. {
  240. LoadResString(IDS_STATUS_NOTYET , pszStatusCode , MAX_STRING_LENGTH );
  241. }
  242. break;
  243. case SCHED_S_TASK_HAS_NOT_RUN:
  244. hr = pITask->GetExitCode(&dwExitCode);
  245. if (FAILED(hr))
  246. {
  247. LoadResString(IDS_STATUS_COULDNOTSTART , pszStatusCode , MAX_STRING_LENGTH );
  248. }
  249. else
  250. {
  251. LoadResString(IDS_STATUS_NOTYET , pszStatusCode , MAX_STRING_LENGTH );
  252. }
  253. break;
  254. case SCHED_S_TASK_DISABLED:
  255. hr = pITask->GetExitCode(&dwExitCode);
  256. if (FAILED(hr))
  257. {
  258. LoadResString(IDS_STATUS_COULDNOTSTART , pszStatusCode , MAX_STRING_LENGTH );
  259. }
  260. else
  261. {
  262. LoadResString(IDS_STATUS_NOTYET , pszStatusCode , MAX_STRING_LENGTH );
  263. }
  264. break;
  265. default:
  266. LoadResString(IDS_STATUS_UNKNOWN , pszStatusCode , MAX_STRING_LENGTH );
  267. break;
  268. }
  269. return S_OK;
  270. }
  271. /******************************************************************************
  272. Routine Description:
  273. This function returns the path of the scheduled task application
  274. Arguments:
  275. [ in ] pITask : Pointer to the ITask interface
  276. [ out ] pszApplicationName : pointer to the Task's scheduled application name
  277. Return Value:
  278. A HRESULT value indicating S_OK on success else S_FALSE on failure
  279. ******************************************************************************/
  280. HRESULT
  281. GetApplicationToRun(ITask* pITask,_TCHAR* pszApplicationName)
  282. {
  283. LPWSTR lpwszApplicationName = NULL;
  284. LPWSTR lpwszParameters = NULL;
  285. _TCHAR szAppName[MAX_STRING_LENGTH] = NULL_STRING;
  286. _TCHAR szParams[MAX_STRING_LENGTH] = NULL_STRING;
  287. // get the entire path of application name
  288. HRESULT hr = pITask->GetApplicationName(&lpwszApplicationName);
  289. if (FAILED(hr))
  290. {
  291. return hr;
  292. }
  293. // get the parameters
  294. hr = pITask->GetParameters(&lpwszParameters);
  295. if (FAILED(hr))
  296. {
  297. return hr;
  298. }
  299. if ( GetCompatibleStringFromUnicode(lpwszApplicationName,szAppName,
  300. SIZE_OF_ARRAY(szAppName)) == NULL )
  301. {
  302. return S_FALSE;
  303. }
  304. if ( GetCompatibleStringFromUnicode(lpwszParameters, szParams,
  305. SIZE_OF_ARRAY(szParams)) == NULL )
  306. {
  307. return S_FALSE;
  308. }
  309. if(lstrlen(szAppName) == 0)
  310. {
  311. lstrcpy(pszApplicationName,NULL_STRING);
  312. }
  313. else
  314. {
  315. lstrcat( szAppName, _T(" ") );
  316. lstrcat( szAppName, szParams );
  317. lstrcpy( pszApplicationName, szAppName);
  318. }
  319. CoTaskMemFree(lpwszApplicationName);
  320. CoTaskMemFree(lpwszParameters);
  321. return S_OK;
  322. }
  323. /******************************************************************************
  324. Routine Description:
  325. This function returns the WorkingDirectory of the scheduled task application
  326. Arguments:
  327. [ in ] pITask : Pointer to the ITask interface
  328. [ out ] pszWorkDir : pointer to the Task's scheduled application working
  329. directory
  330. Return Value:
  331. A HRESULT value indicating S_OK on success else S_FALSE on failure
  332. ******************************************************************************/
  333. HRESULT
  334. GetWorkingDirectory(ITask* pITask,_TCHAR* pszWorkDir)
  335. {
  336. LPWSTR lpwszWorkDir = NULL;
  337. _TCHAR szWorkDir[MAX_STRING_LENGTH] = NULL_STRING;
  338. HRESULT hr = S_OK;
  339. hr = pITask->GetWorkingDirectory(&lpwszWorkDir);
  340. if(FAILED(hr))
  341. {
  342. return hr;
  343. }
  344. if ( GetCompatibleStringFromUnicode(lpwszWorkDir,szWorkDir,
  345. SIZE_OF_ARRAY(szWorkDir)) == NULL )
  346. {
  347. return S_FALSE;
  348. }
  349. if(lstrlen(szWorkDir) == 0)
  350. {
  351. lstrcpy(pszWorkDir,NULL_STRING);
  352. }
  353. else
  354. {
  355. lstrcpy(pszWorkDir,szWorkDir);
  356. }
  357. CoTaskMemFree(lpwszWorkDir);
  358. return S_OK;
  359. }
  360. /******************************************************************************
  361. Routine Description:
  362. This function returns the comment of a task
  363. Arguments:
  364. [ in ] pITask : Pointer to the ITask interface
  365. [ in ] pszComment : pointer to the Task's comment name
  366. Return Value:
  367. A HRESULT value indicating S_OK on success else S_FALSE on failure
  368. ********************************************************************************/
  369. HRESULT
  370. GetComment(ITask* pITask,_TCHAR* pszComment)
  371. {
  372. LPWSTR lpwszComment = NULL;
  373. _TCHAR szTaskComment[MAX_STRING_LENGTH] = NULL_STRING;
  374. HRESULT hr = S_OK;
  375. hr = pITask->GetComment(&lpwszComment);
  376. if (FAILED(hr))
  377. {
  378. return hr;
  379. }
  380. if ( GetCompatibleStringFromUnicode(lpwszComment,szTaskComment,
  381. SIZE_OF_ARRAY(szTaskComment)) == NULL )
  382. {
  383. return S_FALSE;
  384. }
  385. if(lstrlen(szTaskComment) == 0)
  386. {
  387. lstrcpy(pszComment,NULL_STRING);
  388. }
  389. else
  390. {
  391. lstrcpy(pszComment,szTaskComment);
  392. }
  393. CoTaskMemFree(lpwszComment);
  394. return S_OK;
  395. }
  396. /******************************************************************************
  397. Routine Description:
  398. This function returns the creator name of a task
  399. Arguments:
  400. [ in ] pITask : Pointer to the ITask interface
  401. [ in ] pszCreator : pointer to the Task's creator name
  402. Return Value:
  403. A HRESULT value indicating S_OK on success else S_FALSE on failure
  404. *******************************************************************************/
  405. HRESULT
  406. GetCreator(ITask* pITask,_TCHAR* pszCreator)
  407. {
  408. LPWSTR lpwszCreator = NULL;
  409. _TCHAR szTaskCreator[MAX_STRING_LENGTH] = NULL_STRING;
  410. HRESULT hr = S_OK;
  411. hr = pITask->GetCreator(&lpwszCreator);
  412. if (FAILED(hr))
  413. {
  414. return hr;
  415. }
  416. if ( GetCompatibleStringFromUnicode(lpwszCreator,szTaskCreator,
  417. SIZE_OF_ARRAY(szTaskCreator)) == NULL )
  418. {
  419. return S_FALSE;
  420. }
  421. if(lstrlen(szTaskCreator) == 0)
  422. {
  423. lstrcpy(pszCreator,NULL_STRING);
  424. }
  425. else
  426. {
  427. lstrcpy(pszCreator,szTaskCreator);
  428. }
  429. CoTaskMemFree(lpwszCreator);
  430. return S_OK;
  431. }
  432. /******************************************************************************
  433. Routine Description:
  434. This function returns the Trigger string of a task
  435. Arguments:
  436. [ in ] pITask : Pointer to the ITask interface
  437. [ out ] pszTrigger : pointer to the Task's trigger string
  438. Return Value:
  439. A HRESULT value indicating S_OK on success else S_FALSE on failure
  440. ******************************************************************************/
  441. HRESULT
  442. GetTriggerString(ITask* pITask,_TCHAR* pszTrigger,WORD wTriggNum)
  443. {
  444. LPWSTR lpwszTrigger = NULL;
  445. _TCHAR szTaskTrigger[MAX_STRING_LENGTH] = NULL_STRING;
  446. HRESULT hr = S_OK;
  447. hr = pITask->GetTriggerString(wTriggNum,&lpwszTrigger);
  448. if (FAILED(hr))
  449. {
  450. return hr;
  451. }
  452. if (GetCompatibleStringFromUnicode(lpwszTrigger,szTaskTrigger,
  453. SIZE_OF_ARRAY(szTaskTrigger)) == NULL )
  454. {
  455. return S_FALSE;
  456. }
  457. if(lstrlen(szTaskTrigger) == 0)
  458. {
  459. lstrcpy(pszTrigger,NULL_STRING);
  460. }
  461. else
  462. {
  463. lstrcpy(pszTrigger,szTaskTrigger);
  464. }
  465. CoTaskMemFree(lpwszTrigger);
  466. return S_OK;
  467. }
  468. /******************************************************************************
  469. Routine Description:
  470. This function returns the user name of task
  471. Arguments:
  472. [ in ] pITask : Pointer to the ITask interface
  473. [ out ] pszRunAsUser : pointer to the user's task name
  474. Return Value:
  475. A HRESULT value indicating S_OK on success else S_FALSE on failure
  476. *******************************************************************************/
  477. HRESULT
  478. GetRunAsUser(ITask* pITask,_TCHAR* pszRunAsUser)
  479. {
  480. LPWSTR lpwszUser = NULL;
  481. _TCHAR szUserName[MAX_STRING_LENGTH] = NULL_STRING;
  482. HRESULT hr = S_OK;
  483. hr = pITask->GetAccountInformation(&lpwszUser);
  484. if (FAILED(hr))
  485. {
  486. CoTaskMemFree(lpwszUser);
  487. return hr;
  488. }
  489. if ( GetCompatibleStringFromUnicode(lpwszUser,szUserName,
  490. SIZE_OF_ARRAY(szUserName)) == NULL )
  491. {
  492. return S_FALSE;
  493. }
  494. if(lstrlen(szUserName) == 0)
  495. {
  496. lstrcpy(pszRunAsUser,NULL_STRING);
  497. }
  498. else
  499. {
  500. lstrcpy(pszRunAsUser,szUserName);
  501. }
  502. CoTaskMemFree(lpwszUser);
  503. return S_OK;
  504. }
  505. /******************************************************************************
  506. Routine Description:
  507. This function returns the Maximium run time of a task.
  508. Arguments:
  509. [ in ] pITask : Pointer to the ITask interface
  510. [ out ] pszMaxRunTime : pointer to the Task's Maximum run time
  511. Return Value:
  512. A HRESULT value indicating S_OK on success else S_FALSE on failure
  513. ******************************************************************************/
  514. HRESULT
  515. GetMaxRunTime(ITask* pITask,_TCHAR* pszMaxRunTime)
  516. {
  517. DWORD dwRunTime = 0;
  518. DWORD dwHrs = 0;
  519. DWORD dwMins = 0;
  520. //Get the task max run time in milliseconds
  521. HRESULT hr = pITask->GetMaxRunTime(&dwRunTime);
  522. if (FAILED(hr))
  523. {
  524. return hr;
  525. }
  526. dwHrs = (dwRunTime / (1000 * 60 * 60));//Convert ms to hours
  527. dwMins = (dwRunTime % (1000 * 60 * 60));//get the minutes portion
  528. dwMins /= (1000 * 60);// Now convert to Mins
  529. if( (( dwHrs > 999 ) && ( dwMins > 99 )) ||(( dwHrs == 0 ) && ( dwMins == 0 ) ) )
  530. {
  531. //dwHrs = 0;
  532. //dwMins = 0;
  533. lstrcpy( pszMaxRunTime , GetResString(IDS_TASK_PROPERTY_DISABLED) );
  534. }
  535. else if ( dwHrs == 0 )
  536. {
  537. if( dwMins < 99 )
  538. {
  539. FORMAT_STRING2(pszMaxRunTime,_T("%d:%d"),dwHrs,dwMins);
  540. }
  541. }
  542. else if ( (dwHrs < 999) && (dwMins < 99) )
  543. {
  544. FORMAT_STRING2(pszMaxRunTime,_T("%d:%d"),dwHrs,dwMins);
  545. }
  546. else
  547. {
  548. lstrcpy( pszMaxRunTime , GetResString(IDS_TASK_PROPERTY_DISABLED) );
  549. }
  550. return S_OK;
  551. }
  552. /******************************************************************************
  553. Routine Description:
  554. This function returns the state of the task properties
  555. Arguments:
  556. [ in ] pITask : Pointer to the ITask interface
  557. [ out ] pszTaskState : pointer holding the task's state
  558. [ in ] dwFlagType : flag indicating the task state
  559. Return Value:
  560. A HRESULT value indicating S_OK on success else S_FALSE on failure
  561. ********************************************************************************/
  562. HRESULT
  563. GetTaskState(ITask* pITask,_TCHAR* pszTaskState,DWORD dwFlagType)
  564. {
  565. DWORD dwFlags = 0;
  566. HRESULT hr = S_OK;
  567. hr = pITask->GetFlags(&dwFlags);
  568. if(FAILED(hr))
  569. {
  570. return hr;
  571. }
  572. if(dwFlagType == TASK_FLAG_DISABLED)
  573. {
  574. if((dwFlags & dwFlagType) == dwFlagType)
  575. {
  576. LoadResString(IDS_TASK_PROPERTY_DISABLED , pszTaskState , MAX_STRING_LENGTH );
  577. }
  578. else
  579. {
  580. LoadResString(IDS_TASK_PROPERTY_ENABLED , pszTaskState , MAX_STRING_LENGTH );
  581. }
  582. return S_OK;
  583. }
  584. if((dwFlags & dwFlagType) == dwFlagType)
  585. {
  586. LoadResString(IDS_TASK_PROPERTY_ENABLED , pszTaskState , MAX_STRING_LENGTH );
  587. }
  588. else
  589. {
  590. LoadResString(IDS_TASK_PROPERTY_DISABLED , pszTaskState , MAX_STRING_LENGTH );
  591. }
  592. return S_OK;
  593. }
  594. /******************************************************************************
  595. Routine Description:
  596. This function retrives the task properties [modfier,task nextrun time etc]
  597. Arguments:
  598. [ in ] pITask : Pointer to the ITask interface
  599. [ out ] pTaskProps : pointer to the array of task properties
  600. Return Value:
  601. A HRESULT value indicating S_OK on success else S_FALSE on failure
  602. ******************************************************************************/
  603. HRESULT
  604. GetTaskProps(ITask* pITask,TASKPROPS* pTaskProps,WORD wTriggNum, _TCHAR* pszScName)
  605. {
  606. _TCHAR szWeekDay[MAX_STRING_LENGTH] = NULL_STRING;
  607. _TCHAR szMonthDay[MAX_STRING_LENGTH] = NULL_STRING;
  608. _TCHAR szWeek[MAX_STRING_LENGTH] = NULL_STRING;
  609. _TCHAR szTime[MAX_DATETIME_LEN] = NULL_STRING;
  610. _TCHAR szDate[MAX_DATETIME_LEN] = NULL_STRING;
  611. _TCHAR* szValues[3] = {NULL,NULL,NULL};//for holding values of parameters in FormatMessage()
  612. _TCHAR szBuffer[MAX_RES_STRING] = NULL_STRING;
  613. _TCHAR szTempBuf[MAX_RES_STRING] = NULL_STRING;
  614. _TCHAR szScheduleName[MAX_RES_STRING] = NULL_STRING;
  615. ITaskTrigger *pITaskTrigger = NULL;
  616. HRESULT hr = S_OK;
  617. _TCHAR *szToken = NULL;
  618. _TCHAR seps[] = _T(" ");
  619. BOOL bMin = FALSE;
  620. BOOL bHour = FALSE;
  621. DWORD dwMinutes = 0;
  622. DWORD dwHours = 0;
  623. DWORD dwMinInterval = 0;
  624. DWORD dwMinDuration = 0;
  625. if ( lstrlen(pszScName) != 0)
  626. {
  627. lstrcpy(szScheduleName, pszScName);
  628. }
  629. hr = pITask->GetTrigger(wTriggNum,&pITaskTrigger);
  630. if (FAILED(hr))
  631. {
  632. if(pITaskTrigger)
  633. {
  634. pITaskTrigger->Release();
  635. }
  636. return hr;
  637. }
  638. TASK_TRIGGER Trigger;
  639. ZeroMemory(&Trigger, sizeof (TASK_TRIGGER));
  640. hr = pITaskTrigger->GetTrigger(&Trigger);
  641. if (FAILED(hr))
  642. {
  643. if(pITaskTrigger)
  644. {
  645. pITaskTrigger->Release();
  646. }
  647. return hr;
  648. }
  649. //Get the task start time & start date
  650. hr = GetTaskRunTime(pITask,szTime,szDate,TASK_START_RUNTIME,wTriggNum);
  651. if (FAILED(hr))
  652. {
  653. lstrcpy( pTaskProps->szTaskStartTime , GetResString(IDS_TASK_PROPERTY_NA) );
  654. }
  655. else
  656. {
  657. lstrcpy( pTaskProps->szTaskStartTime , szTime );
  658. lstrcpy(pTaskProps->szTaskStartDate, szDate );
  659. }
  660. //Initialize to default values
  661. lstrcpy(pTaskProps->szRepeatEvery, GetResString(IDS_TASK_PROPERTY_DISABLED));
  662. lstrcpy(pTaskProps->szRepeatUntilTime, GetResString(IDS_TASK_PROPERTY_DISABLED));
  663. lstrcpy(pTaskProps->szRepeatDuration, GetResString(IDS_TASK_PROPERTY_DISABLED));
  664. lstrcpy(pTaskProps->szRepeatStop, GetResString(IDS_TASK_PROPERTY_DISABLED));
  665. if((Trigger.TriggerType >= TASK_TIME_TRIGGER_ONCE ) &&
  666. (Trigger.TriggerType <= TASK_TIME_TRIGGER_MONTHLYDOW ))
  667. {
  668. if(Trigger.MinutesInterval > 0)
  669. {
  670. // Getting the minute interval
  671. dwMinInterval = Trigger.MinutesInterval;
  672. if ( dwMinInterval >= 60)
  673. {
  674. // convert minutes into hours
  675. dwHours = dwMinInterval / 60;
  676. szValues[0] = _ultot(dwHours,szBuffer,10);
  677. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  678. GetResString(IDS_RPTTIME_PROPERTY_HOURS),0,MAKELANGID(LANG_NEUTRAL,
  679. SUBLANG_DEFAULT),pTaskProps->szRepeatEvery,
  680. MAX_RES_STRING,(va_list*)szValues
  681. );
  682. }
  683. else
  684. {
  685. szValues[0] = _ultot(dwMinInterval,szBuffer,10);
  686. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  687. GetResString(IDS_RPTTIME_PROPERTY_MINUTES),0,MAKELANGID(LANG_NEUTRAL,
  688. SUBLANG_DEFAULT),pTaskProps->szRepeatEvery,
  689. MAX_RES_STRING,(va_list*)szValues
  690. );
  691. }
  692. if ( dwMinInterval )
  693. {
  694. lstrcpy(pTaskProps->szRepeatUntilTime, GetResString(IDS_TASK_PROPERTY_NONE));
  695. }
  696. // Getting the minute duration
  697. dwMinDuration = Trigger.MinutesDuration;
  698. dwHours = dwMinDuration / 60;
  699. dwMinutes = dwMinDuration % 60;
  700. szValues[0] = _ultot(dwHours,szBuffer,10);
  701. szValues[1] = _ultot(dwMinutes,szTempBuf,10);
  702. FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  703. GetResString(IDS_RPTDURATION_PROPERTY),0,MAKELANGID(LANG_NEUTRAL,
  704. SUBLANG_DEFAULT),pTaskProps->szRepeatDuration,
  705. MAX_RES_STRING,(va_list*)szValues
  706. );
  707. }
  708. }
  709. lstrcpy(pTaskProps->szTaskMonths, GetResString(IDS_TASK_PROPERTY_NA));
  710. switch(Trigger.TriggerType)
  711. {
  712. case TASK_TIME_TRIGGER_ONCE:
  713. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_ONCE));
  714. lstrcpy(pTaskProps->szTaskEndDate,GetResString(IDS_TASK_PROPERTY_NA));
  715. lstrcpy(pTaskProps->szTaskMonths, GetResString(IDS_TASK_PROPERTY_NA));
  716. lstrcpy(pTaskProps->szTaskDays,GetResString(IDS_TASK_PROPERTY_NA) );
  717. break;
  718. case TASK_TIME_TRIGGER_DAILY :
  719. szToken = _tcstok( szScheduleName, seps );
  720. if ( szToken != NULL )
  721. {
  722. szToken = _tcstok( NULL , seps );
  723. if ( szToken != NULL )
  724. {
  725. szToken = _tcstok( NULL , seps );
  726. }
  727. if ( szToken != NULL )
  728. {
  729. if (lstrcmpi(szToken, GetResString( IDS_TASK_HOURLY )) == 0)
  730. {
  731. bHour = TRUE;
  732. }
  733. else if (lstrcmpi(szToken, GetResString( IDS_TASK_MINUTE )) == 0)
  734. {
  735. bMin = TRUE;
  736. }
  737. }
  738. }
  739. if ( bHour == TRUE )
  740. {
  741. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_HOURLY));
  742. }
  743. else if ( bMin == TRUE )
  744. {
  745. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_MINUTE));
  746. }
  747. else
  748. {
  749. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_DAILY));
  750. }
  751. lstrcpy(pTaskProps->szTaskDays, GetResString(IDS_DAILY_TYPE));
  752. break;
  753. case TASK_TIME_TRIGGER_WEEKLY :
  754. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_WEEKLY));
  755. CheckWeekDay(Trigger.Type.Weekly.rgfDaysOfTheWeek,szWeekDay);
  756. lstrcpy(pTaskProps->szTaskDays,szWeekDay);
  757. break;
  758. case TASK_TIME_TRIGGER_MONTHLYDATE :
  759. {
  760. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_MONTHLY));
  761. CheckMonth(Trigger.Type.MonthlyDate.rgfMonths ,szMonthDay);
  762. DWORD dwDays = (Trigger.Type.MonthlyDate.rgfDays);
  763. DWORD dwModdays = 0;
  764. DWORD dw = 0x0; //loop counter
  765. DWORD dwTemp = 0x1;
  766. DWORD dwBits = sizeof(DWORD) * 8; //total no. of bits in a DWORD.
  767. //find out the day no.by finding out which particular bit is set
  768. for(dw = 0; dw <= dwBits; dw++)
  769. {
  770. if( (dwDays & dwTemp) == dwDays )
  771. dwModdays = dw + 1;
  772. dwTemp = dwTemp << 1;
  773. }
  774. FORMAT_STRING(pTaskProps->szTaskDays,_T("%d"),dwModdays);
  775. lstrcpy(pTaskProps->szTaskMonths,szMonthDay);
  776. }
  777. break;
  778. case TASK_TIME_TRIGGER_MONTHLYDOW:
  779. lstrcpy(pTaskProps->szTaskType,GetResString(IDS_TASK_PROPERTY_MONTHLY));
  780. CheckWeek(Trigger.Type.MonthlyDOW.wWhichWeek,szWeek);
  781. CheckWeekDay(Trigger.Type.MonthlyDOW.rgfDaysOfTheWeek,szWeekDay);
  782. lstrcpy(pTaskProps->szTaskDays,szWeekDay);
  783. CheckMonth(Trigger.Type.MonthlyDOW.rgfMonths,szMonthDay);
  784. FORMAT_STRING(pTaskProps->szTaskMonths,_T("%s"),szMonthDay);
  785. break;
  786. case TASK_EVENT_TRIGGER_ON_IDLE :
  787. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_IDLE));
  788. lstrcpy(pTaskProps->szTaskDays,pTaskProps->szTaskMonths);
  789. lstrcpy(pTaskProps->szTaskEndDate, GetResString(IDS_TASK_PROPERTY_NA));
  790. if(pITaskTrigger)
  791. pITaskTrigger->Release();
  792. return S_OK;
  793. case TASK_EVENT_TRIGGER_AT_SYSTEMSTART :
  794. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_SYSSTART));
  795. lstrcpy(pTaskProps->szTaskEndDate, GetResString(IDS_TASK_PROPERTY_NA));
  796. lstrcpy(pTaskProps->szTaskDays, pTaskProps->szTaskMonths);
  797. if(pITaskTrigger)
  798. pITaskTrigger->Release();
  799. return S_OK;
  800. case TASK_EVENT_TRIGGER_AT_LOGON :
  801. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_LOGON));
  802. lstrcpy(pTaskProps->szTaskEndDate, GetResString(IDS_TASK_PROPERTY_NA));
  803. lstrcpy(pTaskProps->szTaskDays, pTaskProps->szTaskMonths);
  804. if(pITaskTrigger)
  805. pITaskTrigger->Release();
  806. return S_OK;
  807. default:
  808. lstrcpy(pTaskProps->szTaskType, GetResString(IDS_TASK_PROPERTY_UNDEF));
  809. lstrcpy(pTaskProps->szTaskEndDate, pTaskProps->szTaskType);
  810. lstrcpy(pTaskProps->szTaskDays, pTaskProps->szTaskType);
  811. lstrcpy(pTaskProps->szTaskStartTime, pTaskProps->szTaskType);
  812. lstrcpy(pTaskProps->szTaskStartDate, pTaskProps->szTaskType);
  813. if(pITaskTrigger)
  814. pITaskTrigger->Release();
  815. return S_OK;
  816. }
  817. //Determine whether the end date is specified.
  818. int iBuffSize = 0;//buffer to know how many TCHARs for end date
  819. SYSTEMTIME tEndDate = {0,0,0,0,0,0,0,0 };
  820. LCID lcid;
  821. BOOL bLocaleChanged = FALSE;
  822. // verify whether console supports the current locale fully or not
  823. lcid = GetSupportedUserLocale( bLocaleChanged );
  824. if((Trigger.rgFlags & TASK_TRIGGER_FLAG_HAS_END_DATE ) == TASK_TRIGGER_FLAG_HAS_END_DATE)
  825. {
  826. tEndDate.wMonth = Trigger.wEndMonth;
  827. tEndDate.wDay = Trigger.wEndDay;
  828. tEndDate.wYear = Trigger.wEndYear;
  829. iBuffSize = GetDateFormat(LOCALE_USER_DEFAULT,0,
  830. &tEndDate,(( bLocaleChanged == TRUE ) ? L"MM/dd/yyyy" : NULL),pTaskProps->szTaskEndDate,0);
  831. if(iBuffSize)
  832. {
  833. GetDateFormat(LOCALE_USER_DEFAULT,0,
  834. &tEndDate,(( bLocaleChanged == TRUE ) ? L"MM/dd/yyyy" : NULL),pTaskProps->szTaskEndDate,iBuffSize);
  835. }
  836. else
  837. {
  838. lstrcpy( pTaskProps->szTaskEndDate , GetResString(IDS_TASK_PROPERTY_NA));
  839. }
  840. }
  841. else
  842. {
  843. lstrcpy(pTaskProps->szTaskEndDate,GetResString(IDS_QUERY_NOENDDATE));
  844. }
  845. if(pITaskTrigger)
  846. pITaskTrigger->Release();
  847. return S_OK;
  848. }
  849. /******************************************************************************
  850. Routine Description:
  851. This function checks the week modifier[ -monthly option] & returns the app.week
  852. day.
  853. Arguments:
  854. [ in ] dwFlag : Flag indicating the week type
  855. [ out ] pWhichWeek : address of pointer containing the week string
  856. Return Value :
  857. None
  858. ******************************************************************************/
  859. VOID
  860. CheckWeek(DWORD dwFlag,_TCHAR* pWhichWeek)
  861. {
  862. lstrcpy(pWhichWeek,NULL_STRING);
  863. if( dwFlag == TASK_FIRST_WEEK )
  864. {
  865. lstrcat(pWhichWeek, GetResString(IDS_TASK_FIRSTWEEK));
  866. lstrcat(pWhichWeek,COMMA_STRING);
  867. }
  868. if( dwFlag == TASK_SECOND_WEEK )
  869. {
  870. lstrcat(pWhichWeek, GetResString(IDS_TASK_SECONDWEEK));
  871. lstrcat(pWhichWeek,COMMA_STRING);
  872. }
  873. if( dwFlag == TASK_THIRD_WEEK )
  874. {
  875. lstrcat(pWhichWeek, GetResString(IDS_TASK_THIRDWEEK));
  876. lstrcat(pWhichWeek,COMMA_STRING);
  877. }
  878. if( dwFlag == TASK_FOURTH_WEEK )
  879. {
  880. lstrcat(pWhichWeek, GetResString(IDS_TASK_FOURTHWEEK));
  881. lstrcat(pWhichWeek,COMMA_STRING);
  882. }
  883. if( dwFlag == TASK_LAST_WEEK )
  884. {
  885. lstrcat(pWhichWeek, GetResString(IDS_TASK_LASTWEEK));
  886. lstrcat(pWhichWeek,COMMA_STRING);
  887. }
  888. int iLen = lstrlen(pWhichWeek);
  889. if(iLen)
  890. *( ( pWhichWeek ) + iLen - lstrlen( COMMA_STRING ) ) = NULL_CHAR;
  891. }
  892. /******************************************************************************
  893. Routine Description:
  894. This function checks the days in the week & returns the app. day.
  895. Arguments:
  896. [ in ] dwFlag : Flag indicating the day type
  897. [ out ] pWeekDay : resulting day string
  898. Return Value :
  899. None
  900. ******************************************************************************/
  901. VOID
  902. CheckWeekDay(DWORD dwFlag,_TCHAR* pWeekDay)
  903. {
  904. lstrcpy(pWeekDay,NULL_STRING);
  905. if((dwFlag & TASK_SUNDAY) == TASK_SUNDAY)
  906. {
  907. lstrcat(pWeekDay, GetResString(IDS_TASK_SUNDAY));
  908. lstrcat(pWeekDay,COMMA_STRING);
  909. }
  910. if((dwFlag & TASK_MONDAY) == TASK_MONDAY)
  911. {
  912. lstrcat(pWeekDay, GetResString(IDS_TASK_MONDAY));
  913. lstrcat(pWeekDay,COMMA_STRING);
  914. }
  915. if((dwFlag & TASK_TUESDAY) == TASK_TUESDAY)
  916. {
  917. lstrcat(pWeekDay, GetResString(IDS_TASK_TUESDAY));
  918. lstrcat(pWeekDay,COMMA_STRING);
  919. }
  920. if((dwFlag & TASK_WEDNESDAY) == TASK_WEDNESDAY)
  921. {
  922. lstrcat(pWeekDay, GetResString(IDS_TASK_WEDNESDAY));
  923. lstrcat(pWeekDay,COMMA_STRING);
  924. }
  925. if((dwFlag & TASK_THURSDAY) == TASK_THURSDAY)
  926. {
  927. lstrcat(pWeekDay, GetResString(IDS_TASK_THURSDAY));
  928. lstrcat(pWeekDay,COMMA_STRING);
  929. }
  930. if((dwFlag& TASK_FRIDAY) == TASK_FRIDAY)
  931. {
  932. lstrcat(pWeekDay, GetResString(IDS_TASK_FRIDAY));
  933. lstrcat(pWeekDay,COMMA_STRING);
  934. }
  935. if((dwFlag & TASK_SATURDAY)== TASK_SATURDAY)
  936. {
  937. lstrcat(pWeekDay, GetResString(IDS_TASK_SATURDAY));
  938. lstrcat(pWeekDay,COMMA_STRING);
  939. }
  940. //Remove the comma from the end of the string.
  941. int iLen = lstrlen(pWeekDay);
  942. if(iLen)
  943. {
  944. *( ( pWeekDay ) + iLen - lstrlen( COMMA_STRING ) ) = NULL_CHAR;
  945. }
  946. }
  947. /******************************************************************************
  948. Routine Description:
  949. This function checks the months in a year & returns the app.Month(s)
  950. Arguments:
  951. [ in ] dwFlag : Flag indicating the Month type
  952. [ out ] pWhichMonth : resulting Month string
  953. Return Value :
  954. None
  955. ******************************************************************************/
  956. VOID
  957. CheckMonth(DWORD dwFlag,_TCHAR* pWhichMonth)
  958. {
  959. lstrcpy(pWhichMonth,NULL_STRING);
  960. if((dwFlag & TASK_JANUARY) == TASK_JANUARY)
  961. {
  962. lstrcat(pWhichMonth, GetResString(IDS_TASK_JANUARY));
  963. lstrcat(pWhichMonth,COMMA_STRING);
  964. }
  965. if((dwFlag & TASK_FEBRUARY) == TASK_FEBRUARY)
  966. {
  967. lstrcat(pWhichMonth, GetResString(IDS_TASK_FEBRUARY));
  968. lstrcat(pWhichMonth,COMMA_STRING);
  969. }
  970. if((dwFlag & TASK_MARCH) == TASK_MARCH)
  971. {
  972. lstrcat(pWhichMonth, GetResString(IDS_TASK_MARCH));
  973. lstrcat(pWhichMonth,COMMA_STRING);
  974. }
  975. if((dwFlag & TASK_APRIL) == TASK_APRIL)
  976. {
  977. lstrcat(pWhichMonth, GetResString(IDS_TASK_APRIL));
  978. lstrcat(pWhichMonth,COMMA_STRING);
  979. }
  980. if((dwFlag & TASK_MAY) == TASK_MAY)
  981. {
  982. lstrcat(pWhichMonth, GetResString(IDS_TASK_MAY));
  983. lstrcat(pWhichMonth,COMMA_STRING);
  984. }
  985. if((dwFlag& TASK_JUNE) == TASK_JUNE)
  986. {
  987. lstrcat(pWhichMonth, GetResString(IDS_TASK_JUNE));
  988. lstrcat(pWhichMonth,COMMA_STRING);
  989. }
  990. if((dwFlag & TASK_JULY)== TASK_JULY)
  991. {
  992. lstrcat(pWhichMonth, GetResString(IDS_TASK_JULY));
  993. lstrcat(pWhichMonth,COMMA_STRING);
  994. }
  995. if((dwFlag & TASK_AUGUST)== TASK_AUGUST)
  996. {
  997. lstrcat(pWhichMonth, GetResString(IDS_TASK_AUGUST));
  998. lstrcat(pWhichMonth,COMMA_STRING);
  999. }
  1000. if((dwFlag & TASK_SEPTEMBER)== TASK_SEPTEMBER)
  1001. {
  1002. lstrcat(pWhichMonth, GetResString(IDS_TASK_SEPTEMBER));
  1003. lstrcat(pWhichMonth,COMMA_STRING);
  1004. }
  1005. if((dwFlag & TASK_OCTOBER)== TASK_OCTOBER)
  1006. {
  1007. lstrcat(pWhichMonth, GetResString(IDS_TASK_OCTOBER));
  1008. lstrcat(pWhichMonth,COMMA_STRING);
  1009. }
  1010. if((dwFlag & TASK_NOVEMBER)== TASK_NOVEMBER)
  1011. {
  1012. lstrcat(pWhichMonth, GetResString(IDS_TASK_NOVEMBER));
  1013. lstrcat(pWhichMonth,COMMA_STRING);
  1014. }
  1015. if((dwFlag & TASK_DECEMBER)== TASK_DECEMBER)
  1016. {
  1017. lstrcat(pWhichMonth, GetResString(IDS_TASK_DECEMBER));
  1018. lstrcat(pWhichMonth,COMMA_STRING);
  1019. }
  1020. int iLen = lstrlen(pWhichMonth);
  1021. //Remove the comma from the end of the string.
  1022. if(iLen)
  1023. {
  1024. *( ( pWhichMonth ) + iLen - lstrlen( COMMA_STRING ) ) = NULL_CHAR;
  1025. }
  1026. }
  1027. /******************************************************************************
  1028. Routine Description:
  1029. This function checks whether the current locale supported by our tool or not.
  1030. Arguments:
  1031. [ out ] bLocaleChanged : Locale change flag
  1032. Return Value :
  1033. None
  1034. ******************************************************************************/
  1035. LCID GetSupportedUserLocale( BOOL& bLocaleChanged )
  1036. {
  1037. // local variables
  1038. LCID lcid;
  1039. // get the current locale
  1040. lcid = GetUserDefaultLCID();
  1041. // check whether the current locale is supported by our tool or not
  1042. // if not change the locale to the english which is our default locale
  1043. bLocaleChanged = FALSE;
  1044. if ( PRIMARYLANGID( lcid ) == LANG_ARABIC || PRIMARYLANGID( lcid ) == LANG_HEBREW ||
  1045. PRIMARYLANGID( lcid ) == LANG_THAI || PRIMARYLANGID( lcid ) == LANG_HINDI ||
  1046. PRIMARYLANGID( lcid ) == LANG_TAMIL || PRIMARYLANGID( lcid ) == LANG_FARSI )
  1047. {
  1048. bLocaleChanged = TRUE;
  1049. lcid = MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ), SORT_DEFAULT ); // 0x409;
  1050. }
  1051. // return the locale
  1052. return lcid;
  1053. }