Leaked source code of windows server 2003
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.

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