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.

2365 lines
82 KiB

  1. /******************************************************************************
  2. Copyright(c) Microsoft Corporation
  3. Module Name:
  4. change.cpp
  5. Abstract:
  6. This module changes the parameters of task(s) present in the system
  7. Author:
  8. Venu Gopal Choudary 01-Mar-2001
  9. Revision History:
  10. Venu Gopal Choudary 01-Mar-2001 : Created it
  11. ******************************************************************************/
  12. //common header files needed for this file
  13. #include "pch.h"
  14. #include "CommonHeaderFiles.h"
  15. // Function declaration for the Usage function.
  16. DWORD DisplayChangeUsage();
  17. BOOL GetTheUserName( LPWSTR pszUserName, DWORD dwMaxUserNameSize );
  18. /*****************************************************************************
  19. Routine Description:
  20. This routine Changes the paraemters of a specified scheduled task(s)
  21. Arguments:
  22. [ in ] argc : Number of command line arguments
  23. [ in ] argv : Array containing command line arguments
  24. Return Value :
  25. A DWORD value indicating EXIT_SUCCESS on success else
  26. EXIT_FAILURE on failure
  27. *****************************************************************************/
  28. DWORD
  29. ChangeScheduledTaskParams(
  30. IN DWORD argc,
  31. IN LPCTSTR argv[]
  32. )
  33. {
  34. // Variables used to find whether Change option, Usage option
  35. // are specified or not
  36. //BOOL bChange = FALSE;
  37. //BOOL bUsage = FALSE;
  38. // Set the TaskSchduler object as NULL
  39. ITaskScheduler *pITaskScheduler = NULL;
  40. // Return value
  41. HRESULT hr = S_OK;
  42. // Declarations related to Task name
  43. LPWSTR wszUserName = NULL;
  44. LPWSTR wszPassword = NULL;
  45. WCHAR wszApplName[_MAX_FNAME] ;
  46. // Dynamic Array contaning array of jobs
  47. TARRAY arrJobs = NULL;
  48. //buffer for displaying error message
  49. WCHAR szMessage[ 2 * MAX_JOB_LEN ] = L"\0";
  50. BOOL bUserName = TRUE;
  51. BOOL bPassWord = TRUE;
  52. BOOL bSystemStatus = FALSE;
  53. //BOOL bNeedPassword = FALSE;
  54. BOOL bResult = FALSE;
  55. BOOL bCloseConnection = TRUE;
  56. DWORD dwPolicy = 0;
  57. TCMDPARSER2 cmdChangeOptions[MAX_CHANGE_OPTIONS];
  58. //BOOL bReturn = FALSE;
  59. SecureZeroMemory ( wszApplName, SIZE_OF_ARRAY(wszApplName));
  60. // declarations of structures
  61. TCHANGESUBOPTS tchgsubops;
  62. TCHANGEOPVALS tchgoptvals;
  63. //Initialize structures to neutral values.
  64. //SecureZeroMemory( &cmdChangeOptions, sizeof( TCMDPARSER2 ) * MAX_CHANGE_OPTIONS);
  65. SecureZeroMemory( &tchgsubops, sizeof( TCHANGESUBOPTS ) );
  66. SecureZeroMemory( &tchgoptvals, sizeof( TCHANGEOPVALS ) );
  67. BOOL bReturn = FALSE;
  68. // /change sub-options
  69. const WCHAR szChangeOpt[] = L"change";
  70. const WCHAR szChangeHelpOpt[] = L"?";
  71. const WCHAR szChangeServerOpt[] = L"s";
  72. const WCHAR szChangeUserOpt[] = L"u";
  73. const WCHAR szChangePwdOpt[] = L"p";
  74. const WCHAR szChangeRunAsUserOpt[] = L"ru";
  75. const WCHAR szChangeRunAsPwdOpt[] = L"rp";
  76. const WCHAR szChangeTaskNameOpt[] = L"tn";
  77. const WCHAR szChangeTaskRunOpt[] = L"tr";
  78. const WCHAR szChangeStartTimeOpt[] = L"st";
  79. const WCHAR szChangeEndTimeOpt[] = L"et";
  80. const WCHAR szChangeStartDateOpt[] = L"sd";
  81. const WCHAR szChangeEndDateOpt[] = L"ed";
  82. const WCHAR szChangeKillAtDurOpt[] = L"k";
  83. const WCHAR szChangeDurationOpt[] = L"du";
  84. const WCHAR szChangeInteractiveOpt[] = L"it";
  85. const WCHAR szChangeStatusOn[] = L"enable";
  86. const WCHAR szChangeStatusOff[] = L"disable";
  87. const WCHAR szChangeDelIfNotSchedOpt[] = L"z";
  88. const WCHAR szChangeRepeatIntervalOpt[] = L"ri";
  89. //
  90. // fill the commandline parser
  91. //
  92. // set all the fields to 0
  93. SecureZeroMemory( cmdChangeOptions, sizeof( TCMDPARSER2 ) * MAX_CHANGE_OPTIONS );
  94. // /change option
  95. StringCopyA( cmdChangeOptions[ OI_CHANGE_OPTION ].szSignature, "PARSER2\0", 8 );
  96. cmdChangeOptions[ OI_CHANGE_OPTION ].dwType = CP_TYPE_BOOLEAN;
  97. cmdChangeOptions[ OI_CHANGE_OPTION ].pwszOptions = szChangeOpt;
  98. cmdChangeOptions[ OI_CHANGE_OPTION ].dwCount = 1;
  99. cmdChangeOptions[ OI_CHANGE_OPTION ].dwFlags = 0;
  100. cmdChangeOptions[ OI_CHANGE_OPTION ].pValue = &tchgsubops.bChange;
  101. // /? option
  102. StringCopyA( cmdChangeOptions[ OI_CHANGE_USAGE ].szSignature, "PARSER2\0", 8 );
  103. cmdChangeOptions[ OI_CHANGE_USAGE ].dwType = CP_TYPE_BOOLEAN;
  104. cmdChangeOptions[ OI_CHANGE_USAGE ].pwszOptions = szChangeHelpOpt;
  105. cmdChangeOptions[ OI_CHANGE_USAGE ].dwCount = 1;
  106. cmdChangeOptions[ OI_CHANGE_USAGE ].dwFlags = CP2_USAGE;
  107. cmdChangeOptions[ OI_CHANGE_USAGE ].pValue = &tchgsubops.bUsage;
  108. // /s option
  109. StringCopyA( cmdChangeOptions[ OI_CHANGE_SERVER ].szSignature, "PARSER2\0", 8 );
  110. cmdChangeOptions[ OI_CHANGE_SERVER ].dwType = CP_TYPE_TEXT;
  111. cmdChangeOptions[ OI_CHANGE_SERVER ].pwszOptions = szChangeServerOpt;
  112. cmdChangeOptions[ OI_CHANGE_SERVER ].dwCount = 1;
  113. cmdChangeOptions[ OI_CHANGE_SERVER ].dwFlags = CP2_ALLOCMEMORY| CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL ;
  114. // /u option
  115. StringCopyA( cmdChangeOptions[ OI_CHANGE_USERNAME ].szSignature, "PARSER2\0", 8 );
  116. cmdChangeOptions[ OI_CHANGE_USERNAME ].dwType = CP_TYPE_TEXT;
  117. cmdChangeOptions[ OI_CHANGE_USERNAME ].pwszOptions = szChangeUserOpt;
  118. cmdChangeOptions[ OI_CHANGE_USERNAME ].dwCount = 1;
  119. cmdChangeOptions[ OI_CHANGE_USERNAME ].dwFlags = CP2_ALLOCMEMORY | CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL ;
  120. // /p option
  121. StringCopyA( cmdChangeOptions[ OI_CHANGE_PASSWORD ].szSignature, "PARSER2\0", 8 );
  122. cmdChangeOptions[ OI_CHANGE_PASSWORD ].dwType = CP_TYPE_TEXT;
  123. cmdChangeOptions[ OI_CHANGE_PASSWORD ].pwszOptions = szChangePwdOpt;
  124. cmdChangeOptions[ OI_CHANGE_PASSWORD ].dwCount = 1;
  125. cmdChangeOptions[ OI_CHANGE_PASSWORD ].dwActuals = 0;
  126. cmdChangeOptions[ OI_CHANGE_PASSWORD ].dwFlags = CP2_ALLOCMEMORY | CP2_VALUE_OPTIONAL ;
  127. // /ru option
  128. StringCopyA( cmdChangeOptions[ OI_CHANGE_RUNASUSER ].szSignature, "PARSER2\0", 8 );
  129. cmdChangeOptions[ OI_CHANGE_RUNASUSER ].dwType = CP_TYPE_TEXT;
  130. cmdChangeOptions[ OI_CHANGE_RUNASUSER ].pwszOptions = szChangeRunAsUserOpt;
  131. cmdChangeOptions[ OI_CHANGE_RUNASUSER ].dwCount = 1;
  132. cmdChangeOptions[ OI_CHANGE_RUNASUSER ].dwFlags = CP2_ALLOCMEMORY| CP2_VALUE_TRIMINPUT;
  133. // /rp option
  134. StringCopyA( cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].szSignature, "PARSER2\0", 8 );
  135. cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].dwType = CP_TYPE_TEXT;
  136. cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].pwszOptions = szChangeRunAsPwdOpt;
  137. cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].dwCount = 1;
  138. cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].dwFlags = CP2_ALLOCMEMORY | CP2_VALUE_OPTIONAL;
  139. // /st option
  140. StringCopyA( cmdChangeOptions[ OI_CHANGE_STARTTIME ].szSignature, "PARSER2\0", 8 );
  141. cmdChangeOptions[ OI_CHANGE_STARTTIME ].dwType = CP_TYPE_TEXT;
  142. cmdChangeOptions[ OI_CHANGE_STARTTIME ].pwszOptions = szChangeStartTimeOpt;
  143. cmdChangeOptions[ OI_CHANGE_STARTTIME ].dwCount = 1;
  144. cmdChangeOptions[ OI_CHANGE_STARTTIME ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  145. cmdChangeOptions[ OI_CHANGE_STARTTIME ].pValue = tchgsubops.szStartTime;
  146. cmdChangeOptions[ OI_CHANGE_STARTTIME ].dwLength = MAX_STRING_LENGTH;
  147. // /sd option
  148. StringCopyA( cmdChangeOptions[ OI_CHANGE_STARTDATE ].szSignature, "PARSER2\0", 8 );
  149. cmdChangeOptions[ OI_CHANGE_STARTDATE ].dwType = CP_TYPE_TEXT;
  150. cmdChangeOptions[ OI_CHANGE_STARTDATE ].pwszOptions = szChangeStartDateOpt;
  151. cmdChangeOptions[ OI_CHANGE_STARTDATE ].dwCount = 1;
  152. cmdChangeOptions[ OI_CHANGE_STARTDATE ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  153. cmdChangeOptions[ OI_CHANGE_STARTDATE ].pValue = tchgsubops.szStartDate;
  154. cmdChangeOptions[ OI_CHANGE_STARTDATE ].dwLength = MAX_STRING_LENGTH;
  155. // /ed option
  156. StringCopyA( cmdChangeOptions[ OI_CHANGE_ENDDATE ].szSignature, "PARSER2\0", 8 );
  157. cmdChangeOptions[ OI_CHANGE_ENDDATE ].dwType = CP_TYPE_TEXT;
  158. cmdChangeOptions[ OI_CHANGE_ENDDATE ].pwszOptions = szChangeEndDateOpt;
  159. cmdChangeOptions[ OI_CHANGE_ENDDATE ].dwCount = 1;
  160. cmdChangeOptions[ OI_CHANGE_ENDDATE ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  161. cmdChangeOptions[ OI_CHANGE_ENDDATE ].pValue = tchgsubops.szEndDate;
  162. cmdChangeOptions[ OI_CHANGE_ENDDATE ].dwLength = MAX_STRING_LENGTH;
  163. // /et option
  164. StringCopyA( cmdChangeOptions[ OI_CHANGE_ENDTIME ].szSignature, "PARSER2\0", 8 );
  165. cmdChangeOptions[ OI_CHANGE_ENDTIME ].dwType = CP_TYPE_TEXT;
  166. cmdChangeOptions[ OI_CHANGE_ENDTIME ].pwszOptions = szChangeEndTimeOpt;
  167. cmdChangeOptions[ OI_CHANGE_ENDTIME ].dwCount = 1;
  168. cmdChangeOptions[ OI_CHANGE_ENDTIME ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  169. cmdChangeOptions[ OI_CHANGE_ENDTIME ].pValue = &tchgsubops.szEndTime;
  170. cmdChangeOptions[ OI_CHANGE_ENDTIME ].dwLength = MAX_STRING_LENGTH;
  171. // /k option
  172. StringCopyA( cmdChangeOptions[ OI_CHANGE_DUR_END ].szSignature, "PARSER2\0", 8 );
  173. cmdChangeOptions[ OI_CHANGE_DUR_END ].dwType = CP_TYPE_BOOLEAN ;
  174. cmdChangeOptions[ OI_CHANGE_DUR_END ].pwszOptions = szChangeKillAtDurOpt ;
  175. cmdChangeOptions[ OI_CHANGE_DUR_END ].dwCount = 1 ;
  176. cmdChangeOptions[ OI_CHANGE_DUR_END ].pValue = &tchgsubops.bIsDurEnd;
  177. // /du option
  178. StringCopyA( cmdChangeOptions[ OI_CHANGE_DURATION ].szSignature, "PARSER2\0", 8 );
  179. cmdChangeOptions[ OI_CHANGE_DURATION ].dwType = CP_TYPE_TEXT;
  180. cmdChangeOptions[ OI_CHANGE_DURATION ].pwszOptions = szChangeDurationOpt;
  181. cmdChangeOptions[ OI_CHANGE_DURATION ].dwCount = 1;
  182. cmdChangeOptions[ OI_CHANGE_DURATION ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  183. cmdChangeOptions[ OI_CHANGE_DURATION ].pValue = tchgsubops.szDuration;
  184. cmdChangeOptions[ OI_CHANGE_DURATION ].dwLength = MAX_STRING_LENGTH;
  185. // /tn option
  186. StringCopyA( cmdChangeOptions[ OI_CHANGE_TASKNAME ].szSignature, "PARSER2\0", 8 );
  187. cmdChangeOptions[ OI_CHANGE_TASKNAME ].dwType = CP_TYPE_TEXT;
  188. cmdChangeOptions[ OI_CHANGE_TASKNAME ].pwszOptions = szChangeTaskNameOpt;
  189. cmdChangeOptions[ OI_CHANGE_TASKNAME ].dwCount = 1;
  190. cmdChangeOptions[ OI_CHANGE_TASKNAME ].dwFlags = CP2_MANDATORY;
  191. cmdChangeOptions[ OI_CHANGE_TASKNAME ].pValue = tchgsubops.szTaskName;
  192. cmdChangeOptions[ OI_CHANGE_TASKNAME ].dwLength = MAX_JOB_LEN;
  193. // /tr option
  194. StringCopyA( cmdChangeOptions[ OI_CHANGE_TASKRUN ].szSignature, "PARSER2\0", 8 );
  195. cmdChangeOptions[ OI_CHANGE_TASKRUN ].dwType = CP_TYPE_TEXT;
  196. cmdChangeOptions[ OI_CHANGE_TASKRUN ].pwszOptions = szChangeTaskRunOpt;
  197. cmdChangeOptions[ OI_CHANGE_TASKRUN ].dwCount = 1;
  198. cmdChangeOptions[ OI_CHANGE_TASKRUN ].dwFlags = CP2_VALUE_TRIMINPUT|CP2_VALUE_NONULL ;
  199. cmdChangeOptions[ OI_CHANGE_TASKRUN ].pValue = tchgsubops.szTaskRun;
  200. cmdChangeOptions[ OI_CHANGE_TASKRUN ].dwLength = MAX_TASK_LEN;
  201. // /it option
  202. StringCopyA( cmdChangeOptions[ OI_CHANGE_IT ].szSignature, "PARSER2\0", 8 );
  203. cmdChangeOptions[ OI_CHANGE_IT ].dwType = CP_TYPE_BOOLEAN;
  204. cmdChangeOptions[ OI_CHANGE_IT ].pwszOptions = szChangeInteractiveOpt;
  205. cmdChangeOptions[ OI_CHANGE_IT ].dwCount = 1;
  206. cmdChangeOptions[ OI_CHANGE_IT ].dwFlags = 0;
  207. cmdChangeOptions[ OI_CHANGE_IT ].pValue = &tchgsubops.bInteractive;
  208. // /enable option
  209. StringCopyA( cmdChangeOptions[ OI_CHANGE_ENABLE ].szSignature, "PARSER2\0", 8 );
  210. cmdChangeOptions[ OI_CHANGE_ENABLE ].dwType = CP_TYPE_BOOLEAN;
  211. cmdChangeOptions[ OI_CHANGE_ENABLE ].pwszOptions = szChangeStatusOn;
  212. cmdChangeOptions[ OI_CHANGE_ENABLE ].dwCount = 1;
  213. cmdChangeOptions[ OI_CHANGE_ENABLE ].pValue = &tchgsubops.bEnable;
  214. // /disable option
  215. StringCopyA( cmdChangeOptions[ OI_CHANGE_DISABLE ].szSignature, "PARSER2\0", 8 );
  216. cmdChangeOptions[ OI_CHANGE_DISABLE ].dwType = CP_TYPE_BOOLEAN;
  217. cmdChangeOptions[ OI_CHANGE_DISABLE ].pwszOptions = szChangeStatusOff;
  218. cmdChangeOptions[ OI_CHANGE_DISABLE ].dwCount = 1;
  219. cmdChangeOptions[ OI_CHANGE_DISABLE ].pValue = &tchgsubops.bDisable;
  220. // /z option
  221. StringCopyA( cmdChangeOptions[ OI_CHANGE_DELNOSCHED ].szSignature, "PARSER2\0", 8 );
  222. cmdChangeOptions[ OI_CHANGE_DELNOSCHED ].dwType = CP_TYPE_BOOLEAN;
  223. cmdChangeOptions[ OI_CHANGE_DELNOSCHED ].pwszOptions = szChangeDelIfNotSchedOpt;
  224. cmdChangeOptions[ OI_CHANGE_DELNOSCHED ].dwCount = 1;
  225. cmdChangeOptions[ OI_CHANGE_DELNOSCHED ].pValue = &tchgsubops.bDelIfNotSched;
  226. // /ri option
  227. StringCopyA( cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].szSignature, "PARSER2\0", 8 );
  228. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].dwType = CP_TYPE_TEXT;
  229. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].pwszOptions = szChangeRepeatIntervalOpt;
  230. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].dwCount = 1;
  231. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].dwFlags = CP2_VALUE_TRIMINPUT | CP2_VALUE_NONULL;
  232. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].pValue = tchgsubops.szRepeat;
  233. cmdChangeOptions[ OI_CHANGE_REPEAT_INTERVAL ].dwLength = MAX_STRING_LENGTH;
  234. //parse command line arguments
  235. bReturn = DoParseParam2( argc, argv, 0, SIZE_OF_ARRAY(cmdChangeOptions), cmdChangeOptions, 0);
  236. if( FALSE == bReturn) // Invalid commandline
  237. {
  238. //display an error message
  239. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_INTERNAL );
  240. ReleaseGlobals();
  241. return EXIT_FAILURE;
  242. }
  243. // get the buffer pointers allocated by command line parser
  244. tchgsubops.szServer = (LPWSTR)cmdChangeOptions[ OI_CHANGE_SERVER ].pValue;
  245. tchgsubops.szUserName = (LPWSTR)cmdChangeOptions[ OI_CHANGE_USERNAME ].pValue;
  246. tchgsubops.szPassword = (LPWSTR)cmdChangeOptions[ OI_CHANGE_PASSWORD ].pValue;
  247. tchgsubops.szRunAsUserName = (LPWSTR)cmdChangeOptions[ OI_CHANGE_RUNASUSER ].pValue;
  248. tchgsubops.szRunAsPassword = (LPWSTR)cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].pValue;
  249. // process the options for -change option
  250. if( EXIT_FAILURE == ValidateChangeOptions ( argc, cmdChangeOptions, tchgsubops, tchgoptvals ) )
  251. {
  252. ReleaseChangeMemory(&tchgsubops);
  253. return EXIT_FAILURE;
  254. }
  255. // Displaying change usage if user specified -? with -change option
  256. if( tchgsubops.bUsage == TRUE )
  257. {
  258. DisplayChangeUsage();
  259. //release memory
  260. ReleaseChangeMemory(&tchgsubops);
  261. return EXIT_SUCCESS;
  262. }
  263. // check whether server (-s) and username (-u) only specified along with the command or not
  264. if( ( IsLocalSystem( tchgsubops.szServer ) == FALSE ) || ( cmdChangeOptions[OI_CHANGE_USERNAME].dwActuals == 1 ) )
  265. {
  266. // Establish the connection on a remote machine
  267. bResult = EstablishConnection(tchgsubops.szServer,tchgsubops.szUserName,GetBufferSize(tchgsubops.szUserName)/sizeof(WCHAR),tchgsubops.szPassword,GetBufferSize(tchgsubops.szPassword)/sizeof(WCHAR), tchgoptvals.bNeedPassword );
  268. if (bResult == FALSE)
  269. {
  270. // displays the appropriate error message
  271. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR| SLE_INTERNAL );
  272. ReleaseChangeMemory(&tchgsubops);
  273. return EXIT_FAILURE ;
  274. }
  275. else
  276. {
  277. // though the connection is successfull, some conflict might have occured
  278. switch( GetLastError() )
  279. {
  280. case I_NO_CLOSE_CONNECTION:
  281. bCloseConnection = FALSE;
  282. break;
  283. // check for mismatched credentials
  284. case E_LOCAL_CREDENTIALS:
  285. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  286. {
  287. bCloseConnection = FALSE;
  288. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR| SLE_INTERNAL );
  289. ReleaseChangeMemory(&tchgsubops);
  290. return EXIT_FAILURE;
  291. }
  292. default :
  293. bCloseConnection = TRUE;
  294. }
  295. }
  296. //release memory for password
  297. FreeMemory((LPVOID*) &tchgsubops.szPassword);
  298. }
  299. // Get the task Scheduler object for the system.
  300. pITaskScheduler = GetTaskScheduler( tchgsubops.szServer );
  301. // If the Task Scheduler is not defined then give the error message.
  302. if ( pITaskScheduler == NULL )
  303. {
  304. // close the connection that was established by the utility
  305. if ( bCloseConnection == TRUE )
  306. CloseConnection( tchgsubops.szServer );
  307. Cleanup(pITaskScheduler);
  308. ReleaseChangeMemory(&tchgsubops);
  309. return EXIT_FAILURE;
  310. }
  311. // Validate the Given Task and get as TARRAY in case of taskname
  312. arrJobs = ValidateAndGetTasks( pITaskScheduler, tchgsubops.szTaskName);
  313. if( arrJobs == NULL )
  314. {
  315. StringCchPrintf( szMessage , SIZE_OF_ARRAY(szMessage), GetResString(IDS_TASKNAME_NOTEXIST), _X( tchgsubops.szTaskName ));
  316. ShowMessage(stderr, szMessage );
  317. // close the connection that was established by the utility
  318. if ( bCloseConnection == TRUE )
  319. CloseConnection( tchgsubops.szServer );
  320. Cleanup(pITaskScheduler);
  321. ReleaseChangeMemory(&tchgsubops);
  322. return EXIT_FAILURE;
  323. }
  324. // check whether the group policy prevented user from changing the
  325. // properties of a task or not.
  326. if ( FALSE == GetGroupPolicy( tchgsubops.szServer, tchgsubops.szUserName, TS_KEYPOLICY_DENY_PROPERTIES, &dwPolicy ) )
  327. {
  328. // close the connection that was established by the utility
  329. if ( bCloseConnection == TRUE )
  330. CloseConnection( tchgsubops.szServer );
  331. Cleanup(pITaskScheduler);
  332. ReleaseChangeMemory(&tchgsubops);
  333. return EXIT_FAILURE;
  334. }
  335. if ( dwPolicy > 0 )
  336. {
  337. ShowMessage ( stdout, GetResString (IDS_PREVENT_CHANGE));
  338. // close the connection that was established by the utility
  339. if ( bCloseConnection == TRUE )
  340. CloseConnection( tchgsubops.szServer );
  341. Cleanup(pITaskScheduler);
  342. ReleaseChangeMemory(&tchgsubops);
  343. return EXIT_SUCCESS;
  344. }
  345. IPersistFile *pIPF = NULL;
  346. ITask *pITask = NULL;
  347. ITaskTrigger *pITaskTrig = NULL;
  348. WORD wTrigNumber = 0;
  349. TASK_TRIGGER TaskTrig;
  350. SecureZeroMemory(&TaskTrig, sizeof (TASK_TRIGGER));
  351. TaskTrig.cbTriggerSize = sizeof (TASK_TRIGGER);
  352. TaskTrig.Reserved1 = 0; // reserved field and must be set to 0.
  353. TaskTrig.Reserved2 = 0; // reserved field and must be set to 0.
  354. //sub-variabes
  355. WORD wStartDay = 0;
  356. WORD wStartMonth = 0;
  357. WORD wStartYear = 0;
  358. WORD wStartHour = 0;
  359. WORD wStartMin = 0;
  360. WORD wEndHour = 0;
  361. WORD wEndMin = 0;
  362. WORD wEndDay = 0;
  363. WORD wEndYear = 0;
  364. WORD wEndMonth = 0;
  365. StringConcat ( tchgsubops.szTaskName, JOB, SIZE_OF_ARRAY(tchgsubops.szTaskName) );
  366. // returns an pITask inteface for szTaskName
  367. hr = pITaskScheduler->Activate(tchgsubops.szTaskName,IID_ITask,
  368. (IUnknown**) &pITask);
  369. if (FAILED(hr))
  370. {
  371. SetLastError ((DWORD) hr);
  372. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  373. if( pIPF )
  374. pIPF->Release();
  375. if( pITask )
  376. pITask->Release();
  377. // close the connection that was established by the utility
  378. if ( bCloseConnection == TRUE )
  379. CloseConnection( tchgsubops.szServer );
  380. Cleanup(pITaskScheduler);
  381. ReleaseChangeMemory(&tchgsubops);
  382. return EXIT_FAILURE;
  383. }
  384. //if the user name is not specifed set the current logged on user settings
  385. DWORD dwTaskFlags = 0;
  386. BOOL bFlag = FALSE;
  387. //WCHAR szBuffer[2 * MAX_STRING_LENGTH] = L"\0";
  388. WCHAR szRunAsUser[MAX_STRING_LENGTH];
  389. WCHAR* szValues[2] = {NULL};//To pass to FormatMessage() API
  390. StringCopy ( szRunAsUser, L"", SIZE_OF_ARRAY(szRunAsUser));
  391. if ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 )
  392. {
  393. wszUserName = tchgsubops.szRunAsUserName;
  394. bUserName = TRUE;
  395. }
  396. else
  397. {
  398. // get the run as user name for a specified scheduled task
  399. hr = GetRunAsUser(pITask, szRunAsUser);
  400. if (FAILED(hr))
  401. {
  402. SetLastError ((DWORD) hr);
  403. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  404. // close the connection that was established by the utility
  405. if ( bCloseConnection == TRUE )
  406. CloseConnection( tchgsubops.szServer );
  407. ReleaseChangeMemory(&tchgsubops);
  408. return EXIT_FAILURE;
  409. }
  410. }
  411. // System account is not applicable with /IT option
  412. if ( (StringLength (szRunAsUser, 0) == 0) && (tchgsubops.bInteractive == TRUE ) &&
  413. ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 0 ))
  414. {
  415. ShowMessage ( stderr, GetResString (IDS_IT_NO_SYSTEM) );
  416. // close the connection that was established by the utility
  417. if ( bCloseConnection == TRUE )
  418. CloseConnection( tchgsubops.szServer );
  419. ReleaseChangeMemory(&tchgsubops);
  420. return EXIT_FAILURE;
  421. }
  422. //check whether /TR option is specified or not
  423. if( cmdChangeOptions[OI_CHANGE_TASKRUN].dwActuals == 1 )
  424. {
  425. // check for .exe substring string in the given task to run string
  426. wchar_t wcszParam[MAX_RES_STRING] = L"\0";
  427. DWORD dwProcessCode = 0 ;
  428. dwProcessCode = ProcessFilePath(tchgsubops.szTaskRun,wszApplName,wcszParam);
  429. if(dwProcessCode == EXIT_FAILURE)
  430. {
  431. if( pIPF )
  432. pIPF->Release();
  433. if( pITask )
  434. pITask->Release();
  435. // close the connection that was established by the utility
  436. if ( bCloseConnection == TRUE )
  437. CloseConnection( tchgsubops.szServer );
  438. Cleanup(pITaskScheduler);
  439. ReleaseChangeMemory(&tchgsubops);
  440. return EXIT_FAILURE;
  441. }
  442. // Set command name with ITask::SetApplicationName
  443. hr = pITask->SetApplicationName(wszApplName);
  444. if (FAILED(hr))
  445. {
  446. SetLastError ((DWORD) hr);
  447. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  448. if( pIPF )
  449. pIPF->Release();
  450. if( pITask )
  451. pITask->Release();
  452. // close the connection that was established by the utility
  453. if ( bCloseConnection == TRUE )
  454. CloseConnection( tchgsubops.szServer );
  455. Cleanup(pITaskScheduler);
  456. ReleaseChangeMemory(&tchgsubops);
  457. return EXIT_FAILURE;
  458. }
  459. //[Working directory = exe pathname - exe name]
  460. wchar_t* wcszStartIn = wcsrchr(wszApplName,_T('\\'));
  461. if(wcszStartIn != NULL)
  462. *( wcszStartIn ) = _T('\0');
  463. // set the working directory of command
  464. hr = pITask->SetWorkingDirectory(wszApplName);
  465. if (FAILED(hr))
  466. {
  467. SetLastError ((DWORD) hr);
  468. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  469. if( pIPF )
  470. pIPF->Release();
  471. if( pITask )
  472. pITask->Release();
  473. // close the connection that was established by the utility
  474. if ( bCloseConnection == TRUE )
  475. CloseConnection( tchgsubops.szServer );
  476. Cleanup(pITaskScheduler);
  477. ReleaseChangeMemory(&tchgsubops);
  478. return EXIT_FAILURE;
  479. }
  480. // set the command line parameters for the task
  481. hr = pITask->SetParameters(wcszParam);
  482. if (FAILED(hr))
  483. {
  484. SetLastError ((DWORD) hr);
  485. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  486. if( pIPF )
  487. {
  488. pIPF->Release();
  489. }
  490. if( pITask )
  491. {
  492. pITask->Release();
  493. }
  494. // close the connection that was established by the utility
  495. if ( bCloseConnection == TRUE )
  496. CloseConnection( tchgsubops.szServer );
  497. Cleanup(pITaskScheduler);
  498. ReleaseChangeMemory(&tchgsubops);
  499. return EXIT_FAILURE;
  500. }
  501. }
  502. // get the flags
  503. hr = pITask->GetFlags(&dwTaskFlags);
  504. if (FAILED(hr))
  505. {
  506. SetLastError ((DWORD) hr);
  507. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  508. if( pIPF )
  509. pIPF->Release();
  510. if( pITask )
  511. pITask->Release();
  512. // close the connection that was established by the utility
  513. if ( bCloseConnection == TRUE )
  514. CloseConnection( tchgsubops.szServer );
  515. Cleanup(pITaskScheduler);
  516. ReleaseChangeMemory(&tchgsubops);
  517. return EXIT_FAILURE;
  518. }
  519. // set flag to run the task interactively
  520. if ( TRUE == tchgsubops.bInteractive )
  521. {
  522. dwTaskFlags |= TASK_FLAG_RUN_ONLY_IF_LOGGED_ON;
  523. }
  524. // remove the .job extension from the taskname
  525. if ( ParseTaskName( tchgsubops.szTaskName ) )
  526. {
  527. if( pIPF )
  528. pIPF->Release();
  529. if( pITask )
  530. pITask->Release();
  531. // close the connection that was established by the utility
  532. if ( bCloseConnection == TRUE )
  533. CloseConnection( tchgsubops.szServer );
  534. Cleanup(pITaskScheduler);
  535. ReleaseChangeMemory(&tchgsubops);
  536. return EXIT_FAILURE;
  537. }
  538. // if /enable is specified
  539. if ( TRUE == tchgsubops.bEnable )
  540. {
  541. // check if task has already been enabled or not
  542. if ( !((dwTaskFlags & TASK_FLAG_DISABLED) == TASK_FLAG_DISABLED ) )
  543. {
  544. StringCchPrintf ( szMessage, SIZE_OF_ARRAY(szMessage), GetResString(IDS_ALREADY_ENABLED), _X(tchgsubops.szTaskName));
  545. // display message as .. task has already been enabled
  546. ShowMessage ( stdout, _X(szMessage));
  547. // if /Enable optional parameter is only specified to change..if the specified
  548. // task has already been enabled.. then return with success
  549. if( TRUE == tchgoptvals.bFlag )
  550. {
  551. if( pIPF )
  552. pIPF->Release();
  553. if( pITask )
  554. pITask->Release();
  555. // close the connection that was established by the utility
  556. if ( bCloseConnection == TRUE )
  557. CloseConnection( tchgsubops.szServer );
  558. Cleanup(pITaskScheduler);
  559. ReleaseChangeMemory(&tchgsubops);
  560. return EXIT_SUCCESS;
  561. }
  562. }
  563. else
  564. {
  565. dwTaskFlags &= ~(TASK_FLAG_DISABLED);
  566. }
  567. }
  568. else if (TRUE == tchgsubops.bDisable ) // if /disable is specified
  569. {
  570. // check if task is already been disabled or not
  571. if ( (dwTaskFlags & TASK_FLAG_DISABLED) == TASK_FLAG_DISABLED )
  572. {
  573. StringCchPrintf ( szMessage, SIZE_OF_ARRAY(szMessage), GetResString(IDS_ALREADY_DISABLED), _X(tchgsubops.szTaskName));
  574. // display message as .. task has already been disabled
  575. ShowMessage ( stdout, _X(szMessage));
  576. // if /Disable optional parameter is only specified to change..if the specified
  577. // task has already been disabled.. then return with success
  578. if( TRUE == tchgoptvals.bFlag )
  579. {
  580. if( pIPF )
  581. pIPF->Release();
  582. if( pITask )
  583. pITask->Release();
  584. // close the connection that was established by the utility
  585. if ( bCloseConnection == TRUE )
  586. CloseConnection( tchgsubops.szServer );
  587. Cleanup(pITaskScheduler);
  588. ReleaseChangeMemory(&tchgsubops);
  589. return EXIT_SUCCESS;
  590. }
  591. }
  592. else
  593. {
  594. dwTaskFlags |= TASK_FLAG_DISABLED;
  595. }
  596. }
  597. // if /n is specified .. enables the falg to delete the task if not scheduled to
  598. // run again...
  599. if ( TRUE == tchgsubops.bDelIfNotSched)
  600. {
  601. dwTaskFlags |= TASK_FLAG_DELETE_WHEN_DONE;
  602. }
  603. // set the flags
  604. hr = pITask->SetFlags(dwTaskFlags);
  605. if (FAILED(hr))
  606. {
  607. SetLastError ((DWORD) hr);
  608. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  609. if( pIPF )
  610. pIPF->Release();
  611. if( pITask )
  612. pITask->Release();
  613. // close the connection that was established by the utility
  614. if ( bCloseConnection == TRUE )
  615. CloseConnection( tchgsubops.szServer );
  616. Cleanup(pITaskScheduler);
  617. ReleaseChangeMemory(&tchgsubops);
  618. return EXIT_FAILURE;
  619. }
  620. if ( bSystemStatus == TRUE )
  621. {
  622. //szValues[0] = (WCHAR*) (tchgsubops.szTaskName);
  623. StringCchPrintf ( szMessage, SIZE_OF_ARRAY(szMessage), GetResString(IDS_NTAUTH_SYSTEM_CHANGE_INFO), _X(tchgsubops.szTaskName));
  624. ShowMessage ( stdout, _X(szMessage));
  625. }
  626. if( (cmdChangeOptions[OI_CHANGE_RUNASPASSWORD].dwActuals == 1) && ( bSystemStatus == TRUE ) &&
  627. (StringLength( tchgsubops.szRunAsPassword, 0 ) != 0) )
  628. {
  629. ShowMessage( stdout, GetResString( IDS_PASSWORD_NOEFFECT ) );
  630. }
  631. //get the trigger for the corresponding task
  632. hr = pITask->GetTrigger(wTrigNumber, &pITaskTrig);
  633. if (FAILED(hr))
  634. {
  635. SetLastError ((DWORD) hr);
  636. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  637. if(pIPF)
  638. pIPF->Release();
  639. if(pITask)
  640. pITask->Release();
  641. if( pITaskTrig )
  642. pITaskTrig->Release();
  643. // close the connection that was established by the utility
  644. if ( bCloseConnection == TRUE )
  645. CloseConnection( tchgsubops.szServer );
  646. Cleanup(pITaskScheduler);
  647. ReleaseChangeMemory(&tchgsubops);
  648. return EXIT_FAILURE;
  649. }
  650. //Get the current task trigger
  651. hr = pITaskTrig->GetTrigger(&TaskTrig);
  652. if (hr != S_OK)
  653. {
  654. SetLastError ((DWORD) hr);
  655. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  656. if(pIPF)
  657. pIPF->Release();
  658. if(pITask)
  659. pITask->Release();
  660. if( pITaskTrig )
  661. pITaskTrig->Release();
  662. // close the connection that was established by the utility
  663. if ( bCloseConnection == TRUE )
  664. CloseConnection( tchgsubops.szServer );
  665. Cleanup(pITaskScheduler);
  666. ReleaseChangeMemory(&tchgsubops);
  667. return EXIT_FAILURE;
  668. }
  669. //sub-variables
  670. DWORD dwRepeat = 0;
  671. DWORD dwEndTimeInMin = 0;
  672. DWORD dwStartTimeInMin = 0;
  673. DWORD dwDuration = 0;
  674. DWORD dwModifierVal = 0;
  675. LPWSTR pszStopString = NULL;
  676. // check whether /SD o /ED is specified for the scheduled type ONETIME
  677. if( ( TaskTrig.TriggerType == TASK_TIME_TRIGGER_ONCE) && (( cmdChangeOptions[OI_CHANGE_STARTDATE].dwActuals == 1 ) ||
  678. ( cmdChangeOptions[OI_CHANGE_ENDDATE].dwActuals == 1 ) ) )
  679. {
  680. // display an error message as.. /SD or /ED is not allowed for ONCE
  681. ShowMessage(stderr, GetResString(IDS_CHANGE_ONCE_NA));
  682. if(pIPF)
  683. pIPF->Release();
  684. if(pITask)
  685. pITask->Release();
  686. if( pITaskTrig )
  687. pITaskTrig->Release();
  688. // close the connection that was established by the utility
  689. if ( bCloseConnection == TRUE )
  690. CloseConnection( tchgsubops.szServer );
  691. Cleanup(pITaskScheduler);
  692. ReleaseChangeMemory(&tchgsubops);
  693. return EXIT_FAILURE;
  694. }
  695. //check whether either /Rt or /Et or /Ri or /Du is specified for the existing scheduled types
  696. // onstart, onlogon and onstart..
  697. if ( ( ( cmdChangeOptions[OI_CHANGE_REPEAT_INTERVAL].dwActuals == 1) ||
  698. ( cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 1) || ( cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 1) ||
  699. ( cmdChangeOptions[OI_CHANGE_ENDDATE].dwActuals == 1) || ( cmdChangeOptions[OI_CHANGE_STARTTIME].dwActuals == 1) ||
  700. ( cmdChangeOptions[OI_CHANGE_STARTDATE].dwActuals == 1) || ( cmdChangeOptions[OI_CHANGE_DUR_END].dwActuals == 1) ) &&
  701. ( (TaskTrig.TriggerType == TASK_EVENT_TRIGGER_ON_IDLE) ||
  702. (TaskTrig.TriggerType == TASK_EVENT_TRIGGER_AT_SYSTEMSTART ) || ( TaskTrig.TriggerType == TASK_EVENT_TRIGGER_AT_LOGON ) ) )
  703. {
  704. ShowMessage (stderr, GetResString (IDS_SCTYPE_NA) );
  705. if(pIPF)
  706. pIPF->Release();
  707. if(pITask)
  708. pITask->Release();
  709. if( pITaskTrig )
  710. pITaskTrig->Release();
  711. // close the connection that was established by the utility
  712. if ( bCloseConnection == TRUE )
  713. CloseConnection( tchgsubops.szServer );
  714. Cleanup(pITaskScheduler);
  715. ReleaseChangeMemory(&tchgsubops);
  716. return EXIT_FAILURE;
  717. }
  718. //If either /DU or /ET is specified and /RI is not specified..
  719. // then set dwRepeat-> actual repetition value
  720. if( (cmdChangeOptions[OI_CHANGE_REPEAT_INTERVAL].dwActuals == 0) &&
  721. ( (cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 1) ||
  722. (cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 1) ) )
  723. {
  724. if ( 0 != TaskTrig.MinutesInterval )
  725. {
  726. dwRepeat = TaskTrig.MinutesInterval;
  727. }
  728. else
  729. {
  730. //repetition interval defaults to 10 minutes
  731. dwRepeat = 10;
  732. }
  733. }
  734. //If either /DU or /ET is not specified and /RI is specified..
  735. // then set dwDuration-> actual duration value
  736. if( ( cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 0 ) && ( cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 0 ) &&
  737. (cmdChangeOptions[OI_CHANGE_REPEAT_INTERVAL].dwActuals == 1) )
  738. {
  739. if ( 0 != TaskTrig.MinutesDuration )
  740. {
  741. dwDuration = TaskTrig.MinutesDuration;
  742. }
  743. else
  744. {
  745. //duration defaults to 10 minutes
  746. dwDuration = 60;
  747. }
  748. }
  749. if( cmdChangeOptions[OI_CHANGE_REPEAT_INTERVAL].dwActuals == 1)
  750. {
  751. // get the repetition value
  752. dwRepeat = wcstol(tchgsubops.szRepeat, &pszStopString, BASE_TEN);
  753. if ((errno == ERANGE) ||
  754. ((pszStopString != NULL) && (StringLength (pszStopString, 0) != 0) ) ||
  755. ( (dwRepeat < MIN_REPETITION_INTERVAL ) || ( dwRepeat > MAX_REPETITION_INTERVAL) ) )
  756. {
  757. // display an error message as .. invalid value specified for /RT
  758. ShowMessage ( stderr, GetResString (IDS_INVALID_RT_VALUE) );
  759. if(pIPF)
  760. pIPF->Release();
  761. if(pITask)
  762. pITask->Release();
  763. if( pITaskTrig )
  764. pITaskTrig->Release();
  765. // close the connection that was established by the utility
  766. if ( bCloseConnection == TRUE )
  767. CloseConnection( tchgsubops.szServer );
  768. Cleanup(pITaskScheduler);
  769. ReleaseChangeMemory(&tchgsubops);
  770. return EXIT_FAILURE;
  771. }
  772. //check whether the specified repetition interval is greater than 9999..
  773. // if so, set the maximum repetition interval as 9999.
  774. if ( (dwRepeat > 9999) && ( (dwRepeat % 60) != 0) )
  775. {
  776. //display some warning message as.. max value (less than the specified interval)
  777. // divisible by 60.
  778. ShowMessage ( stderr, GetResString (IDS_WARN_VALUE) );
  779. dwRepeat -= (dwRepeat % 60);
  780. }
  781. }
  782. // if the start time is specified..set the specified values to the current trigger
  783. if (cmdChangeOptions[ OI_CHANGE_STARTTIME ].dwActuals == 1)
  784. {
  785. // get the Start time in terms of hours, minutes and seconds
  786. GetTimeFieldEntities(tchgsubops.szStartTime, &wStartHour, &wStartMin );
  787. // set the start time
  788. TaskTrig.wStartHour = wStartHour;
  789. TaskTrig.wStartMinute = wStartMin;
  790. }
  791. else
  792. {
  793. // get the values for start time
  794. wStartHour = TaskTrig.wStartHour;
  795. wStartMin = TaskTrig.wStartMinute;
  796. }
  797. //check whether /ET is specified or not
  798. if (cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 1)
  799. {
  800. // get the Start time in terms of hours, minutes and seconds
  801. GetTimeFieldEntities(tchgsubops.szEndTime, &wEndHour, &wEndMin );
  802. // calculate start time in minutes
  803. dwStartTimeInMin = (DWORD) ( wStartHour * MINUTES_PER_HOUR * SECS_PER_MINUTE + wStartMin * SECS_PER_MINUTE )/ SECS_PER_MINUTE ;
  804. // calculate end time in minutes
  805. dwEndTimeInMin = (DWORD) ( wEndHour * MINUTES_PER_HOUR * SECS_PER_MINUTE + wEndMin * SECS_PER_MINUTE ) / SECS_PER_MINUTE ;
  806. // check whether end time is later than start time
  807. if ( dwEndTimeInMin >= dwStartTimeInMin )
  808. {
  809. // if the end and start time in the same day..
  810. // get the duration between end and start time (in minutes)
  811. dwDuration = dwEndTimeInMin - dwStartTimeInMin ;
  812. }
  813. else
  814. {
  815. // if the start and end time not in the same day..
  816. // get the duration between start and end time (in minutes)
  817. // and subtract that duration by 1440(max value in minutes)..
  818. dwDuration = 1440 - (dwStartTimeInMin - dwEndTimeInMin ) ;
  819. }
  820. dwModifierVal = TaskTrig.MinutesInterval ;
  821. //check whether The duration is greater than the repetition interval or not.
  822. if ( dwDuration <= dwModifierVal || dwDuration <= dwRepeat)
  823. {
  824. ShowMessage ( stderr, GetResString (IDS_INVALID_DURATION1) );
  825. if(pIPF)
  826. pIPF->Release();
  827. if(pITask)
  828. pITask->Release();
  829. if( pITaskTrig )
  830. pITaskTrig->Release();
  831. // close the connection that was established by the utility
  832. if ( bCloseConnection == TRUE )
  833. CloseConnection( tchgsubops.szServer );
  834. Cleanup(pITaskScheduler);
  835. ReleaseChangeMemory(&tchgsubops);
  836. return EXIT_FAILURE;
  837. }
  838. }
  839. else if(cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 1)
  840. {
  841. //sub-variables
  842. WCHAR tHours[MAX_RES_STRING];
  843. WCHAR tMins[MAX_RES_STRING];
  844. DWORD dwDurationHours = 0;
  845. DWORD dwDurationMin = 0;
  846. //initialize the variables
  847. SecureZeroMemory (tHours, SIZE_OF_ARRAY(tHours));
  848. SecureZeroMemory (tMins, SIZE_OF_ARRAY(tMins));
  849. if ( ( StringLength (tchgsubops.szDuration, 0) != 7 ) || (tchgsubops.szDuration[4] != TIME_SEPARATOR_CHAR) )
  850. {
  851. ShowMessage ( stderr, GetResString (IDS_INVALIDDURATION_FORMAT) );
  852. if(pIPF)
  853. pIPF->Release();
  854. if(pITask)
  855. pITask->Release();
  856. if( pITaskTrig )
  857. pITaskTrig->Release();
  858. // close the connection that was established by the utility
  859. if ( bCloseConnection == TRUE )
  860. CloseConnection( tchgsubops.szServer );
  861. Cleanup(pITaskScheduler);
  862. ReleaseChangeMemory(&tchgsubops);
  863. return EXIT_FAILURE;
  864. }
  865. StringCopy(tHours, wcstok(tchgsubops.szDuration,TIME_SEPARATOR_STR), SIZE_OF_ARRAY(tHours)); // Get the Hours field.
  866. if(StringLength(tHours, 0) > 0)
  867. {
  868. StringCopy(tMins, wcstok(NULL,TIME_SEPARATOR_STR), SIZE_OF_ARRAY(tMins)); // Get the Minutes field.
  869. }
  870. dwDurationHours = wcstol(tHours, &pszStopString, BASE_TEN);
  871. if ((errno == ERANGE) ||
  872. ((pszStopString != NULL) && (StringLength (pszStopString, 0) != 0) ) )
  873. {
  874. ShowMessage ( stderr, GetResString (IDS_INVALID_DU_VALUE) );
  875. if(pIPF)
  876. pIPF->Release();
  877. if(pITask)
  878. pITask->Release();
  879. if( pITaskTrig )
  880. pITaskTrig->Release();
  881. // close the connection that was established by the utility
  882. if ( bCloseConnection == TRUE )
  883. CloseConnection( tchgsubops.szServer );
  884. Cleanup(pITaskScheduler);
  885. ReleaseChangeMemory(&tchgsubops);
  886. return EXIT_FAILURE;
  887. }
  888. dwDurationHours = dwDurationHours * MINUTES_PER_HOUR;
  889. dwDurationMin = wcstol(tMins, &pszStopString, BASE_TEN);
  890. if ((errno == ERANGE) ||
  891. ((pszStopString != NULL) && (StringLength (pszStopString, 0) != 0) ) )
  892. {
  893. ShowMessage ( stderr, GetResString (IDS_INVALID_DU_VALUE) );
  894. if(pIPF)
  895. pIPF->Release();
  896. if(pITask)
  897. pITask->Release();
  898. if( pITaskTrig )
  899. pITaskTrig->Release();
  900. // close the connection that was established by the utility
  901. if ( bCloseConnection == TRUE )
  902. CloseConnection( tchgsubops.szServer );
  903. Cleanup(pITaskScheduler);
  904. ReleaseChangeMemory(&tchgsubops);
  905. return EXIT_FAILURE;
  906. }
  907. // sum the hours and minutes into minutes
  908. dwDuration = dwDurationHours + dwDurationMin ;
  909. dwModifierVal = TaskTrig.MinutesInterval ;
  910. //check whether The duration is greater than the repetition interval or not.
  911. if ( dwDuration <= dwModifierVal || dwDuration <= dwRepeat)
  912. {
  913. ShowMessage ( stderr, GetResString (IDS_INVALID_DURATION2) );
  914. if(pIPF)
  915. pIPF->Release();
  916. if(pITask)
  917. pITask->Release();
  918. if( pITaskTrig )
  919. pITaskTrig->Release();
  920. // close the connection that was established by the utility
  921. if ( bCloseConnection == TRUE )
  922. CloseConnection( tchgsubops.szServer );
  923. Cleanup(pITaskScheduler);
  924. ReleaseChangeMemory(&tchgsubops);
  925. return EXIT_FAILURE;
  926. }
  927. }
  928. // set the repetition interval and duration values
  929. {
  930. // if repetition interval is not 0.. then set actual value of /RI
  931. if ( 0 != dwRepeat )
  932. {
  933. // set the MinutesInterval
  934. TaskTrig.MinutesInterval = dwRepeat;
  935. }
  936. // if duration is not 0.. set the actual value of /DU
  937. if ( 0 != dwDuration )
  938. {
  939. // set the duration value
  940. TaskTrig.MinutesDuration = dwDuration ;
  941. }
  942. }
  943. //check whether The duration is greater than the repetition interval or not.
  944. if ( (0 != dwRepeat) && ( dwDuration <= dwRepeat ) )
  945. {
  946. ShowMessage ( stderr, GetResString (IDS_INVALID_DURATION2) );
  947. if(pIPF)
  948. pIPF->Release();
  949. if(pITask)
  950. pITask->Release();
  951. if( pITaskTrig )
  952. pITaskTrig->Release();
  953. // close the connection that was established by the utility
  954. if ( bCloseConnection == TRUE )
  955. CloseConnection( tchgsubops.szServer );
  956. Cleanup(pITaskScheduler);
  957. ReleaseChangeMemory(&tchgsubops);
  958. return EXIT_FAILURE;
  959. }
  960. // if the start date is specified..set the specified values to the current trigger
  961. if (cmdChangeOptions[OI_CHANGE_STARTDATE].dwActuals == 1)
  962. {
  963. // get the Start date in terms of day, month and year
  964. GetDateFieldEntities(tchgsubops.szStartDate, &wStartDay, &wStartMonth, &wStartYear);
  965. // set the start time
  966. TaskTrig.wBeginDay = wStartDay;
  967. TaskTrig.wBeginMonth = wStartMonth;
  968. TaskTrig.wBeginYear = wStartYear;
  969. }
  970. else
  971. {
  972. // get the esisting start time
  973. wStartDay = TaskTrig.wBeginDay ;
  974. wStartMonth = TaskTrig.wBeginMonth ;
  975. wStartYear = TaskTrig.wBeginYear ;
  976. }
  977. //check whether /K is specified or not
  978. if ( TRUE == tchgsubops.bIsDurEnd )
  979. {
  980. // set the flag to terminate the task at the end of lifetime.
  981. TaskTrig.rgFlags |= TASK_TRIGGER_FLAG_KILL_AT_DURATION_END ;
  982. }
  983. // if the start time is specified..set the specified values to the current trigger
  984. if (cmdChangeOptions[OI_CHANGE_ENDDATE].dwActuals == 1)
  985. {
  986. // Now set the end date entities.
  987. GetDateFieldEntities(tchgsubops.szEndDate, &wEndDay, &wEndMonth, &wEndYear);
  988. // Make end date valid; otherwise the enddate parameter is ignored.
  989. TaskTrig.rgFlags |= TASK_TRIGGER_FLAG_HAS_END_DATE;
  990. TaskTrig.wEndDay = wEndDay;
  991. TaskTrig.wEndMonth = wEndMonth;
  992. TaskTrig.wEndYear = wEndYear;
  993. }
  994. else
  995. {
  996. // get the esisting end date
  997. wEndDay = TaskTrig.wEndDay ;
  998. wEndMonth = TaskTrig.wEndMonth ;
  999. wEndYear = TaskTrig.wEndYear ;
  1000. }
  1001. if ( (0 != wStartYear) && (0 != wEndYear) )
  1002. {
  1003. //check whether end date is earlier than start date or not
  1004. if( ( wEndYear == wStartYear ) )
  1005. {
  1006. // For same years if the end month is less than start month or for same years and same months
  1007. // if the endday is less than the startday.
  1008. if ( ( wEndMonth < wStartMonth ) || ( ( wEndMonth == wStartMonth ) && ( wEndDay < wStartDay ) ) )
  1009. {
  1010. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  1011. return RETVAL_FAIL;
  1012. }
  1013. }
  1014. else if ( wEndYear < wStartYear )
  1015. {
  1016. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  1017. return RETVAL_FAIL;
  1018. }
  1019. }
  1020. // set the task trigger
  1021. hr = pITaskTrig->SetTrigger(&TaskTrig);
  1022. if (hr != S_OK)
  1023. {
  1024. SetLastError ((DWORD) hr);
  1025. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1026. if(pIPF)
  1027. pIPF->Release();
  1028. if(pITask)
  1029. pITask->Release();
  1030. if( pITaskTrig )
  1031. pITaskTrig->Release();
  1032. // close the connection that was established by the utility
  1033. if ( bCloseConnection == TRUE )
  1034. CloseConnection( tchgsubops.szServer );
  1035. Cleanup(pITaskScheduler);
  1036. ReleaseChangeMemory(&tchgsubops);
  1037. return EXIT_FAILURE;
  1038. }
  1039. /////////////////////////////////////////
  1040. //check for user creentials
  1041. ////////////////////////////////////////
  1042. // Check whether /ru "" or "System" or "Nt Authority\System" for system account
  1043. if ( ( ((tchgsubops.bInteractive == TRUE ) && (StringLength (szRunAsUser, 0) == 0)) || (cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) ) &&
  1044. ( (StringLength( tchgsubops.szRunAsUserName, 0) == 0) || ( StringCompare(tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) ||
  1045. (StringCompare(tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0 ) == 0 ) ) )
  1046. {
  1047. bSystemStatus = TRUE;
  1048. bFlag = TRUE;
  1049. }
  1050. else if ( FAILED (hr) )
  1051. {
  1052. bFlag = TRUE;
  1053. }
  1054. // flag to check whether run as user name is "NT AUTHORITY\SYSTEM" or not
  1055. if ( bFlag == FALSE )
  1056. {
  1057. // check for "NT AUTHORITY\SYSTEM" username
  1058. if( ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringLength( tchgsubops.szRunAsUserName, 0) == 0 ) ) ||
  1059. ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringLength( tchgsubops.szRunAsUserName, 0) == 0 ) && ( StringLength(tchgsubops.szRunAsPassword, 0 ) == 0 ) ) ||
  1060. ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringCompare(tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) && ( StringLength(tchgsubops.szRunAsPassword, 0 ) == 0 )) ||
  1061. ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringCompare(tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) ) ||
  1062. ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringCompare(tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0) == 0 ) && ( StringLength(tchgsubops.szRunAsPassword, 0 ) == 0 ) ) ||
  1063. ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( StringCompare(tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0 ) == 0 ) ) )
  1064. {
  1065. bSystemStatus = TRUE;
  1066. }
  1067. }
  1068. if ( bSystemStatus == FALSE )
  1069. {
  1070. //check the length of run as user name
  1071. if ( (StringLength( tchgsubops.szRunAsUserName, 0 ) != 0 ))
  1072. {
  1073. wszUserName = tchgsubops.szRunAsUserName;
  1074. }
  1075. else if (( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 0 ))
  1076. {
  1077. wszUserName = szRunAsUser;
  1078. bUserName = TRUE;
  1079. }
  1080. else
  1081. {
  1082. bUserName = FALSE;
  1083. }
  1084. //check for the null password
  1085. if ( ( StringLength( tchgsubops.szRunAsPassword, 0 ) != 0 ) && ( StringCompare ( tchgsubops.szRunAsPassword, ASTERIX, TRUE, 0) != 0 ) )
  1086. {
  1087. wszPassword = tchgsubops.szRunAsPassword;
  1088. bPassWord = TRUE;
  1089. }
  1090. else
  1091. {
  1092. // check whether -rp is specified or not
  1093. if (cmdChangeOptions[OI_CHANGE_RUNASPASSWORD].dwActuals == 1)
  1094. {
  1095. if( ( StringCompare( tchgsubops.szRunAsPassword , L"\0", TRUE, 0 ) != 0 ) && ( StringCompare ( tchgsubops.szRunAsPassword, ASTERIX, TRUE, 0) != 0 ) )
  1096. {
  1097. bPassWord = TRUE;
  1098. }
  1099. else if ( ( bSystemStatus == FALSE ) && ( StringLength (tchgsubops.szRunAsPassword, 0) == 0 ) )
  1100. {
  1101. ShowMessage (stderr, GetResString(IDS_WARN_EMPTY_PASSWORD));
  1102. }
  1103. else if ( StringCompare ( tchgsubops.szRunAsPassword, ASTERIX, TRUE, 0) == 0 )
  1104. {
  1105. bPassWord = FALSE;
  1106. }
  1107. }
  1108. else if ( bSystemStatus == FALSE )
  1109. {
  1110. bPassWord = FALSE;
  1111. }
  1112. }
  1113. }
  1114. // check for the status of username and password
  1115. if( ( bUserName == TRUE ) && ( bPassWord == FALSE ) )
  1116. {
  1117. szValues[0] = (WCHAR*) (wszUserName);
  1118. ShowMessageEx ( stderr, 1, FALSE, GetResString(IDS_PROMPT_CHGPASSWD), _X(wszUserName));
  1119. // Get the password from the command line
  1120. if (GetPassword( tchgsubops.szRunAsPassword, GetBufferSize(tchgsubops.szRunAsPassword)/sizeof(WCHAR) ) == FALSE )
  1121. {
  1122. // close the connection that was established by the utility
  1123. if ( bCloseConnection == TRUE )
  1124. {
  1125. CloseConnection( tchgsubops.szServer );
  1126. }
  1127. ReleaseChangeMemory(&tchgsubops);
  1128. return EXIT_FAILURE;
  1129. }
  1130. //check for the null password
  1131. if( StringCompare( tchgsubops.szRunAsPassword , L"\0", TRUE, 0 ) == 0 )
  1132. {
  1133. ShowMessage (stderr, GetResString(IDS_WARN_EMPTY_PASSWORD));
  1134. }
  1135. // check for the password length > 0
  1136. wszPassword = tchgsubops.szRunAsPassword;
  1137. }
  1138. // check for the status of user name and password
  1139. else if( ( bUserName == FALSE ) && ( bPassWord == TRUE ) )
  1140. {
  1141. if ( (bFlag == TRUE ) && ( bSystemStatus == FALSE ) )
  1142. {
  1143. ShowMessage(stdout, GetResString(IDS_PROMPT_USERNAME));
  1144. if ( GetTheUserName( tchgsubops.szRunAsUserName, GetBufferSize(tchgsubops.szRunAsUserName)/sizeof(WCHAR)) == FALSE )
  1145. {
  1146. ShowMessage(stderr, GetResString( IDS_FAILED_TOGET_USER ) );
  1147. // close the connection that was established by the utility
  1148. if ( bCloseConnection == TRUE )
  1149. CloseConnection( tchgsubops.szServer );
  1150. ReleaseChangeMemory(&tchgsubops);
  1151. return EXIT_FAILURE;
  1152. }
  1153. // check for the length of username
  1154. if( StringLength(tchgsubops.szRunAsUserName, 0) > MAX_RES_STRING )
  1155. {
  1156. ShowMessage(stderr,GetResString(IDS_INVALID_UNAME ));
  1157. // close the connection that was established by the utility
  1158. if ( bCloseConnection == TRUE )
  1159. CloseConnection( tchgsubops.szServer );
  1160. ReleaseChangeMemory(&tchgsubops);
  1161. return EXIT_FAILURE;
  1162. }
  1163. if ( (StringLength( tchgsubops.szRunAsUserName, 0) == 0) || ( StringCompare(tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) ||
  1164. (StringCompare(tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0 ) == 0 ) )
  1165. {
  1166. bSystemStatus = TRUE;
  1167. bFlag = TRUE;
  1168. }
  1169. else
  1170. {
  1171. // check for the length of run as user name
  1172. if(StringLength(tchgsubops.szRunAsUserName, 0))
  1173. {
  1174. wszUserName = tchgsubops.szRunAsUserName;
  1175. }
  1176. }
  1177. }
  1178. else
  1179. {
  1180. wszUserName = szRunAsUser;
  1181. }
  1182. // check for the length of password > 0
  1183. wszPassword = tchgsubops.szRunAsPassword;
  1184. }
  1185. // check for the user name and password are not specified
  1186. else if( ( bUserName == FALSE ) && ( bPassWord == FALSE ) )
  1187. {
  1188. if ( (bFlag == TRUE ) && ( bSystemStatus == FALSE ) )
  1189. {
  1190. ShowMessage(stdout, GetResString(IDS_PROMPT_USERNAME));
  1191. if ( GetTheUserName( tchgsubops.szRunAsUserName, GetBufferSize(tchgsubops.szRunAsUserName)/sizeof(WCHAR) ) == FALSE )
  1192. {
  1193. ShowMessage(stderr, GetResString( IDS_FAILED_TOGET_USER ) );
  1194. // close the connection that was established by the utility
  1195. if ( bCloseConnection == TRUE )
  1196. CloseConnection( tchgsubops.szServer );
  1197. ReleaseChangeMemory(&tchgsubops);
  1198. return EXIT_FAILURE;
  1199. }
  1200. // check for the length of username
  1201. if( StringLength(tchgsubops.szRunAsUserName, 0) > MAX_RES_STRING )
  1202. {
  1203. ShowMessage(stderr,GetResString(IDS_INVALID_UNAME ));
  1204. // close the connection that was established by the utility
  1205. if ( bCloseConnection == TRUE )
  1206. CloseConnection( tchgsubops.szServer );
  1207. ReleaseChangeMemory(&tchgsubops);
  1208. return EXIT_FAILURE;
  1209. }
  1210. if ( (StringLength( tchgsubops.szRunAsUserName, 0) == 0) || ( StringCompare(tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) ||
  1211. (StringCompare(tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0 ) == 0 ) )
  1212. {
  1213. bSystemStatus = TRUE;
  1214. bFlag = TRUE;
  1215. }
  1216. else
  1217. {
  1218. if(StringLength(tchgsubops.szRunAsUserName, 0))
  1219. {
  1220. wszUserName = tchgsubops.szRunAsUserName;
  1221. }
  1222. }
  1223. }
  1224. else
  1225. {
  1226. wszUserName = szRunAsUser;
  1227. }
  1228. if ( StringLength ( wszUserName, 0 ) != 0 )
  1229. {
  1230. szValues[0] = (WCHAR*) (wszUserName);
  1231. ShowMessageEx ( stderr, 1, FALSE, GetResString(IDS_PROMPT_CHGPASSWD), _X(wszUserName));
  1232. // Get the run as user password from the command line
  1233. if ( GetPassword( tchgsubops.szRunAsPassword, GetBufferSize(tchgsubops.szRunAsPassword)/sizeof(WCHAR) ) == FALSE )
  1234. {
  1235. // close the connection that was established by the utility
  1236. if ( bCloseConnection == TRUE )
  1237. CloseConnection( tchgsubops.szServer );
  1238. ReleaseChangeMemory(&tchgsubops);
  1239. return EXIT_FAILURE;
  1240. }
  1241. //check for the null password
  1242. if( StringCompare( tchgsubops.szRunAsPassword , L"\0", TRUE, 0 ) == 0 )
  1243. {
  1244. ShowMessage (stderr, GetResString(IDS_WARN_EMPTY_PASSWORD));
  1245. }
  1246. wszPassword = tchgsubops.szRunAsPassword;
  1247. }
  1248. }
  1249. //check for null password
  1250. if ( NULL == wszPassword )
  1251. {
  1252. wszPassword = L"\0";
  1253. }
  1254. // Return a pointer to a specified interface on an object
  1255. hr = pITask->QueryInterface(IID_IPersistFile, (void **) &pIPF);
  1256. if (FAILED(hr))
  1257. {
  1258. SetLastError ((DWORD) hr);
  1259. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1260. if( pIPF )
  1261. pIPF->Release();
  1262. if( pITask )
  1263. pITask->Release();
  1264. // close the connection that was established by the utility
  1265. if ( bCloseConnection == TRUE )
  1266. CloseConnection( tchgsubops.szServer );
  1267. Cleanup(pITaskScheduler);
  1268. ReleaseChangeMemory(&tchgsubops);
  1269. return EXIT_FAILURE;
  1270. }
  1271. //set account information..
  1272. if( bSystemStatus == TRUE )
  1273. {
  1274. // Change the account information to "NT AUTHORITY\SYSTEM" user
  1275. hr = pITask->SetAccountInformation(L"",NULL);
  1276. if ( FAILED(hr) )
  1277. {
  1278. ShowMessage(stderr, GetResString(IDS_NTAUTH_SYSTEM_ERROR));
  1279. if( pIPF )
  1280. pIPF->Release();
  1281. if( pITask )
  1282. pITask->Release();
  1283. // close the connection that was established by the utility
  1284. if ( bCloseConnection == TRUE )
  1285. CloseConnection( tchgsubops.szServer );
  1286. Cleanup(pITaskScheduler);
  1287. ReleaseChangeMemory(&tchgsubops);
  1288. return EXIT_FAILURE;
  1289. }
  1290. }
  1291. else
  1292. {
  1293. // set the account information with the user name and password
  1294. hr = pITask->SetAccountInformation(wszUserName,wszPassword);
  1295. }
  1296. if ((FAILED(hr)) && (hr != SCHED_E_NO_SECURITY_SERVICES))
  1297. {
  1298. SetLastError ((DWORD) hr);
  1299. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1300. if( pIPF )
  1301. pIPF->Release();
  1302. if( pITask )
  1303. pITask->Release();
  1304. // close the connection that was established by the utility
  1305. if ( bCloseConnection == TRUE )
  1306. CloseConnection( tchgsubops.szServer );
  1307. Cleanup(pITaskScheduler);
  1308. ReleaseChangeMemory(&tchgsubops);
  1309. return EXIT_FAILURE;
  1310. }
  1311. ////////////////////////////////////////
  1312. /// Save all the parameters
  1313. ////////////////////////////////////////
  1314. // save the copy of an object
  1315. hr = pIPF->Save(NULL,TRUE);
  1316. if( E_FAIL == hr )
  1317. {
  1318. SetLastError ((DWORD) hr);
  1319. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1320. if(pIPF)
  1321. pIPF->Release();
  1322. if(pITask)
  1323. pITask->Release();
  1324. if( pITaskTrig )
  1325. pITaskTrig->Release();
  1326. // close the connection that was established by the utility
  1327. if ( bCloseConnection == TRUE )
  1328. CloseConnection( tchgsubops.szServer );
  1329. Cleanup(pITaskScheduler);
  1330. ReleaseChangeMemory(&tchgsubops);
  1331. return EXIT_FAILURE;
  1332. }
  1333. if (FAILED (hr))
  1334. {
  1335. SetLastError ((DWORD) hr);
  1336. ShowLastErrorEx ( stderr, SLE_TYPE_ERROR | SLE_SYSTEM );
  1337. if(pIPF)
  1338. pIPF->Release();
  1339. if(pITask)
  1340. pITask->Release();
  1341. if( pITaskTrig )
  1342. pITaskTrig->Release();
  1343. // close the connection that was established by the utility
  1344. if ( bCloseConnection == TRUE )
  1345. CloseConnection( tchgsubops.szServer );
  1346. Cleanup(pITaskScheduler);
  1347. ReleaseChangeMemory(&tchgsubops);
  1348. return EXIT_FAILURE;
  1349. }
  1350. else
  1351. {
  1352. // to display a success message
  1353. //szValues[0] = (WCHAR*) (tchgsubops.szTaskName);
  1354. StringCchPrintf ( szMessage, SIZE_OF_ARRAY(szMessage), GetResString(IDS_CHANGE_SUCCESSFUL), _X(tchgsubops.szTaskName));
  1355. ShowMessage ( stdout, _X(szMessage));
  1356. }
  1357. if( pIPF )
  1358. pIPF->Release();
  1359. if( pITask )
  1360. pITask->Release();
  1361. if( pITaskTrig )
  1362. pITaskTrig->Release();
  1363. // close the connection that was established by the utility
  1364. if ( bCloseConnection == TRUE )
  1365. CloseConnection( tchgsubops.szServer );
  1366. Cleanup(pITaskScheduler);
  1367. ReleaseChangeMemory(&tchgsubops);
  1368. return EXIT_SUCCESS;
  1369. }
  1370. /******************************************************************************
  1371. Routine Description:
  1372. This routine displays the create option usage
  1373. Arguments:
  1374. None
  1375. Return Value :
  1376. DWORD
  1377. ******************************************************************************/
  1378. DWORD
  1379. DisplayChangeUsage()
  1380. {
  1381. WCHAR szTmpBuffer[ 2 * MAX_STRING_LENGTH];
  1382. WCHAR szBuffer[ 2 * MAX_STRING_LENGTH];
  1383. WCHAR szFormat[MAX_DATE_STR_LEN];
  1384. // initialize to zero
  1385. SecureZeroMemory ( szTmpBuffer, SIZE_OF_ARRAY(szTmpBuffer));
  1386. SecureZeroMemory ( szBuffer, SIZE_OF_ARRAY(szBuffer));
  1387. SecureZeroMemory ( szFormat, SIZE_OF_ARRAY(szFormat));
  1388. // get the date format
  1389. if ( GetDateFormatString( szFormat) )
  1390. {
  1391. return EXIT_FAILURE;
  1392. }
  1393. // Displaying Create usage
  1394. for( DWORD dw = IDS_CHANGE_HLP1; dw <= IDS_CHANGE_HLP38; dw++ )
  1395. {
  1396. switch (dw)
  1397. {
  1398. case IDS_CHANGE_HLP30:
  1399. StringCchPrintf ( szTmpBuffer, SIZE_OF_ARRAY(szTmpBuffer), GetResString(IDS_CHANGE_HLP30), _X(szFormat) );
  1400. ShowMessage ( stdout, _X(szTmpBuffer) );
  1401. dw = IDS_CHANGE_HLP30;
  1402. break;
  1403. case IDS_CHANGE_HLP31:
  1404. StringCchPrintf ( szTmpBuffer, SIZE_OF_ARRAY(szTmpBuffer), GetResString(IDS_CHANGE_HLP31), _X(szFormat) );
  1405. ShowMessage ( stdout, _X(szTmpBuffer) );
  1406. dw = IDS_CHANGE_HLP31;
  1407. break;
  1408. default :
  1409. ShowMessage(stdout, GetResString(dw));
  1410. break;
  1411. }
  1412. }
  1413. return EXIT_SUCCESS;
  1414. }
  1415. // ***************************************************************************
  1416. // Routine Description:
  1417. //
  1418. // Takes the user name from the keyboard.While entering the user name
  1419. // it displays the user name as it is.
  1420. //
  1421. // Arguments:
  1422. //
  1423. // [in] pszUserName -- String to store user name
  1424. // [in] dwMaxUserNameSize -- Maximun size of the user name.
  1425. //
  1426. // Return Value:
  1427. //
  1428. // BOOL --If this function succeds returns TRUE otherwise returns FALSE.
  1429. //
  1430. // ***************************************************************************
  1431. BOOL
  1432. GetTheUserName(
  1433. IN LPWSTR pszUserName,
  1434. IN DWORD dwMaxUserNameSize
  1435. )
  1436. {
  1437. // local variables
  1438. WCHAR ch;
  1439. DWORD dwIndex = 0;
  1440. DWORD dwCharsRead = 0;
  1441. DWORD dwCharsWritten = 0;
  1442. DWORD dwPrevConsoleMode = 0;
  1443. HANDLE hInputConsole = NULL;
  1444. WCHAR szBuffer[ 10 ] = L"\0";
  1445. BOOL bFlag = TRUE;
  1446. // check the input value
  1447. if ( pszUserName == NULL )
  1448. {
  1449. SetLastError( ERROR_INVALID_PARAMETER );
  1450. SaveLastError();
  1451. return FALSE;
  1452. }
  1453. // Get the handle for the standard input
  1454. hInputConsole = GetStdHandle( STD_INPUT_HANDLE );
  1455. if ( hInputConsole == NULL )
  1456. {
  1457. // could not get the handle so return failure
  1458. return FALSE;
  1459. }
  1460. // Get the current input mode of the input buffer
  1461. GetConsoleMode( hInputConsole, &dwPrevConsoleMode );
  1462. // Set the mode such that the control keys are processed by the system
  1463. if ( SetConsoleMode( hInputConsole, ENABLE_PROCESSED_INPUT ) == 0 )
  1464. {
  1465. // could not set the mode, return failure
  1466. return FALSE;
  1467. }
  1468. // Read the characters until a carriage return is hit
  1469. do
  1470. {
  1471. if ( ReadConsole( hInputConsole, &ch, 1, &dwCharsRead, NULL ) == 0 )
  1472. {
  1473. // Set the original console settings
  1474. SetConsoleMode( hInputConsole, dwPrevConsoleMode );
  1475. // return failure
  1476. return FALSE;
  1477. }
  1478. // Check for carraige return
  1479. if ( ch == CARRIAGE_RETURN )
  1480. {
  1481. ShowMessage(stdout, _T("\n"));
  1482. bFlag = FALSE;
  1483. // break from the loop
  1484. break;
  1485. }
  1486. // Check id back space is hit
  1487. if ( ch == BACK_SPACE )
  1488. {
  1489. if ( dwIndex != 0 )
  1490. {
  1491. // move the cursor one character back
  1492. StringCchPrintf( szBuffer, SIZE_OF_ARRAY(szBuffer), _T( "%c" ), BACK_SPACE );
  1493. WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), szBuffer, 1,
  1494. &dwCharsWritten, NULL );
  1495. // replace the existing character with space
  1496. StringCchPrintf( szBuffer, SIZE_OF_ARRAY(szBuffer), _T( "%c" ), BLANK_CHAR );
  1497. WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), szBuffer, 1,
  1498. &dwCharsWritten, NULL );
  1499. // now set the cursor at back position
  1500. StringCchPrintf( szBuffer, SIZE_OF_ARRAY(szBuffer), _T( "%c" ), BACK_SPACE );
  1501. WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), szBuffer, 1,
  1502. &dwCharsWritten, NULL );
  1503. // decrement the index
  1504. dwIndex--;
  1505. }
  1506. // process the next character
  1507. continue;
  1508. }
  1509. // if the max user name length has been reached then sound a beep
  1510. if ( dwIndex == ( dwMaxUserNameSize - 1 ) )
  1511. {
  1512. WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), BEEP_SOUND, 1,
  1513. &dwCharsRead, NULL );
  1514. }
  1515. else
  1516. {
  1517. // store the input character
  1518. *( pszUserName + dwIndex ) = ch;
  1519. // display asterix onto the console
  1520. WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), ( pszUserName + dwIndex ) , 1,
  1521. &dwCharsWritten, NULL );
  1522. dwIndex++;
  1523. }
  1524. } while (TRUE == bFlag);
  1525. // Add the NULL terminator
  1526. *( pszUserName + dwIndex ) = L'\0';
  1527. // Return success
  1528. return TRUE;
  1529. }
  1530. /******************************************************************************
  1531. Routine Description:
  1532. This routine parses and validates the options specified by the user &
  1533. determines the type of a scheduled task
  1534. Arguments:
  1535. [ in ] argc : The count of arguments given by the user.
  1536. [ out ] tchgsubops : Structure containing Scheduled task's properties.
  1537. [ out ] tchgoptvals : Structure containing optional properties to set for a
  1538. scheduledtask .
  1539. [ out ] pdwRetScheType : pointer to the type of a schedule task
  1540. [Daily,once,weekly etc].
  1541. [ out ] pbUserStatus : pointer to check whether the -ru is given in
  1542. the command line or not.
  1543. Return Value :
  1544. A DWORD value indicating RETVAL_SUCCESS on success else EXIT_FAILURE
  1545. on failure
  1546. ******************************************************************************/
  1547. DWORD
  1548. ValidateChangeOptions(
  1549. IN DWORD argc,
  1550. OUT TCMDPARSER2 cmdChangeOptions[],
  1551. IN OUT TCHANGESUBOPTS &tchgsubops,
  1552. IN OUT TCHANGEOPVALS &tchgoptvals
  1553. )
  1554. {
  1555. DWORD dwScheduleType = 0;
  1556. // If -ru is not specified allocate the memory
  1557. if ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 0 )
  1558. {
  1559. // password
  1560. if ( tchgsubops.szRunAsUserName == NULL )
  1561. {
  1562. tchgsubops.szRunAsUserName = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1563. if ( tchgsubops.szRunAsUserName == NULL )
  1564. {
  1565. SaveLastError();
  1566. return EXIT_FAILURE;
  1567. }
  1568. }
  1569. }
  1570. // If -rp is not specified allocate the memory
  1571. if ( cmdChangeOptions[OI_CHANGE_RUNASPASSWORD].dwActuals == 0 )
  1572. {
  1573. // password
  1574. if ( tchgsubops.szRunAsPassword == NULL )
  1575. {
  1576. tchgsubops.szRunAsPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1577. if ( tchgsubops.szRunAsPassword == NULL )
  1578. {
  1579. SaveLastError();
  1580. return EXIT_FAILURE;
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if ( cmdChangeOptions[ OI_CHANGE_RUNASPASSWORD ].pValue == NULL )
  1587. {
  1588. tchgsubops.szRunAsPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1589. if ( NULL == tchgsubops.szRunAsPassword)
  1590. {
  1591. SaveLastError();
  1592. return EXIT_FAILURE;
  1593. }
  1594. StringCopy( tchgsubops.szRunAsPassword, L"*", GetBufferSize(tchgsubops.szRunAsPassword)/sizeof(WCHAR));
  1595. }
  1596. }
  1597. //check for /? (usage)
  1598. if ( tchgsubops.bUsage == TRUE )
  1599. {
  1600. if (argc > 3)
  1601. {
  1602. ShowMessage ( stderr, GetResString (IDS_ERROR_CHANGEPARAM) );
  1603. return EXIT_FAILURE;
  1604. }
  1605. else if ( 3 == argc )
  1606. {
  1607. return EXIT_SUCCESS;
  1608. }
  1609. }
  1610. //check whether any optional parameters are specified or not.
  1611. if( ( 0 == cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals ) &&
  1612. ( 0 == cmdChangeOptions[OI_CHANGE_RUNASPASSWORD].dwActuals ) &&
  1613. ( 0 == cmdChangeOptions[OI_CHANGE_TASKRUN].dwActuals ) &&
  1614. ( 0 == cmdChangeOptions[OI_CHANGE_STARTTIME].dwActuals ) &&
  1615. ( 0 == cmdChangeOptions[OI_CHANGE_STARTDATE].dwActuals ) &&
  1616. ( 0 == cmdChangeOptions[OI_CHANGE_ENDDATE].dwActuals ) &&
  1617. ( 0 == cmdChangeOptions[OI_CHANGE_IT].dwActuals ) &&
  1618. ( 0 == cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals ) &&
  1619. ( 0 == cmdChangeOptions[OI_CHANGE_DUR_END].dwActuals ) &&
  1620. ( 0 == cmdChangeOptions[OI_CHANGE_DURATION].dwActuals ) &&
  1621. ( 0 == cmdChangeOptions[OI_CHANGE_DELNOSCHED].dwActuals ) &&
  1622. ( 0 == cmdChangeOptions[OI_CHANGE_REPEAT_INTERVAL].dwActuals ) )
  1623. {
  1624. if ( ( 0 == cmdChangeOptions[OI_CHANGE_ENABLE].dwActuals ) &&
  1625. ( 0 == cmdChangeOptions[OI_CHANGE_DISABLE].dwActuals ) )
  1626. {
  1627. ShowMessage(stderr,GetResString(IDS_NO_CHANGE_OPTIONS));
  1628. return EXIT_FAILURE;
  1629. }
  1630. else
  1631. {
  1632. tchgoptvals.bFlag = TRUE;
  1633. }
  1634. }
  1635. // check whether -u or -ru options specified respectively with -p or -rp options or not
  1636. if ( cmdChangeOptions[ OI_CHANGE_USERNAME ].dwActuals == 0 && cmdChangeOptions[ OI_CHANGE_PASSWORD ].dwActuals == 1 )
  1637. {
  1638. // invalid syntax
  1639. ShowMessage(stderr, GetResString(IDS_CHPASSWORD_BUT_NOUSERNAME));
  1640. return EXIT_FAILURE; // indicate failure
  1641. }
  1642. // check for invalid user name
  1643. if( ( cmdChangeOptions[OI_CHANGE_SERVER].dwActuals == 0 ) && ( cmdChangeOptions[OI_CHANGE_USERNAME].dwActuals == 1 ) )
  1644. {
  1645. ShowMessage(stderr, GetResString(IDS_CHANGE_USER_BUT_NOMACHINE));
  1646. return EXIT_FAILURE;
  1647. }
  1648. // check for /IT switch is not applicable with "NT AUTHORITY\SYSTEM" account
  1649. if ( ( cmdChangeOptions[OI_CHANGE_RUNASUSER].dwActuals == 1 ) && ( ( StringLength ( tchgsubops.szRunAsUserName, 0 ) == 0 ) ||
  1650. ( StringCompare( tchgsubops.szRunAsUserName, NTAUTHORITY_USER, TRUE, 0 ) == 0 ) ||
  1651. ( StringCompare( tchgsubops.szRunAsUserName, SYSTEM_USER, TRUE, 0 ) == 0 ) ) &&
  1652. ( TRUE == tchgsubops.bInteractive ) )
  1653. {
  1654. ShowMessage ( stderr, GetResString (IDS_IT_SWITCH_NA) );
  1655. return EXIT_FAILURE;
  1656. }
  1657. // If -rp is not specified allocate the memory
  1658. if ( cmdChangeOptions[OI_CHANGE_RUNASPASSWORD].dwActuals == 0 )
  1659. {
  1660. // password
  1661. if ( tchgsubops.szRunAsPassword == NULL )
  1662. {
  1663. tchgsubops.szRunAsPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1664. if ( tchgsubops.szRunAsPassword == NULL )
  1665. {
  1666. SaveLastError();
  1667. return EXIT_FAILURE;
  1668. }
  1669. }
  1670. }
  1671. //
  1672. //check for INVALID SYNTAX
  1673. //
  1674. // check for invalid user name
  1675. if( ( cmdChangeOptions[OI_CHANGE_SERVER].dwActuals == 0 ) && ( cmdChangeOptions[OI_CHANGE_USERNAME].dwActuals == 1 ) )
  1676. {
  1677. ShowMessage(stderr, GetResString(IDS_CHANGE_USER_BUT_NOMACHINE));
  1678. //release memory
  1679. ReleaseChangeMemory(&tchgsubops);
  1680. return EXIT_FAILURE;
  1681. }
  1682. // check whether /ET and /DU specified..
  1683. if( ( cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 1 ) && ( cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 1 ) )
  1684. {
  1685. // display an error message as.. /ET and /DU are mutual exclusive
  1686. ShowMessage(stderr, GetResString(IDS_DURATION_NOT_ENDTIME));
  1687. return EXIT_FAILURE;
  1688. }
  1689. if ( ( cmdChangeOptions[OI_CHANGE_DUR_END].dwActuals == 1 ) &&
  1690. ( cmdChangeOptions[OI_CHANGE_DURATION].dwActuals == 0 ) && ( cmdChangeOptions[OI_CHANGE_ENDTIME].dwActuals == 0 ) )
  1691. {
  1692. ShowMessage(stderr, GetResString(IDS_NO_CHANGE_K_OR_RT));
  1693. return EXIT_FAILURE;
  1694. }
  1695. // check whether /enable and /disable options are specified..
  1696. if ( ( TRUE == tchgsubops.bEnable )&& (TRUE == tchgsubops.bDisable ) )
  1697. {
  1698. // display an error message as.. /Enable and /Disable are mutual exclusive
  1699. ShowMessage(stderr, GetResString(IDS_ENABLE_AND_DISABLE));
  1700. return EXIT_FAILURE;
  1701. }
  1702. // Start validations for the sub-options
  1703. if( EXIT_FAILURE == ValidateChangeSuboptVal(tchgsubops, tchgoptvals, cmdChangeOptions, dwScheduleType) )
  1704. {
  1705. return(EXIT_FAILURE);
  1706. }
  1707. return EXIT_SUCCESS;
  1708. }
  1709. /******************************************************************************
  1710. Routine Description:
  1711. This routine validates the sub options specified by the user reg.create option
  1712. & determines the type of a scheduled task.
  1713. Arguments:
  1714. [ out ] tchgsubops : Structure containing the task's properties
  1715. [ out ] tchgoptvals : Structure containing optional values to set
  1716. [ in ] cmdOptions[] : Array of type TCMDPARSER
  1717. [ in ] dwScheduleType : Type of schedule[Daily,once,weekly etc]
  1718. Return Value :
  1719. A DWORD value indicating RETVAL_SUCCESS on success else EXIT_FAILURE
  1720. on failure
  1721. ******************************************************************************/
  1722. DWORD
  1723. ValidateChangeSuboptVal(
  1724. OUT TCHANGESUBOPTS& tchgsubops,
  1725. OUT TCHANGEOPVALS &tchgoptvals,
  1726. IN TCMDPARSER2 cmdOptions[],
  1727. IN DWORD dwScheduleType
  1728. )
  1729. {
  1730. DWORD dwRetval = RETVAL_SUCCESS;
  1731. BOOL bIsStDtCurDt = FALSE;
  1732. // check whether the password (-p) specified in the command line or not
  1733. // and also check whether '*' or empty is given for -p or not
  1734. // check the remote connectivity information
  1735. if ( tchgsubops.szServer != NULL )
  1736. {
  1737. //
  1738. // if -u is not specified, we need to allocate memory
  1739. // in order to be able to retrive the current user name
  1740. //
  1741. // case 1: -p is not at all specified
  1742. // as the value for this switch is optional, we have to rely
  1743. // on the dwActuals to determine whether the switch is specified or not
  1744. // in this case utility needs to try to connect first and if it fails
  1745. // then prompt for the password -- in fact, we need not check for this
  1746. // condition explicitly except for noting that we need to prompt for the
  1747. // password
  1748. //
  1749. // case 2: -p is specified
  1750. // but we need to check whether the value is specified or not
  1751. // in this case user wants the utility to prompt for the password
  1752. // before trying to connect
  1753. //
  1754. // case 3: -p * is specified
  1755. // user name
  1756. if ( tchgsubops.szUserName == NULL )
  1757. {
  1758. tchgsubops.szUserName = (LPWSTR) AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1759. if ( tchgsubops.szUserName == NULL )
  1760. {
  1761. SaveLastError();
  1762. return EXIT_FAILURE;
  1763. }
  1764. }
  1765. // password
  1766. if ( tchgsubops.szPassword == NULL )
  1767. {
  1768. tchgoptvals.bNeedPassword = TRUE;
  1769. tchgsubops.szPassword = (LPWSTR)AllocateMemory( MAX_STRING_LENGTH * sizeof( WCHAR ) );
  1770. if ( tchgsubops.szPassword == NULL )
  1771. {
  1772. SaveLastError();
  1773. return EXIT_FAILURE;
  1774. }
  1775. }
  1776. // case 1
  1777. if ( cmdOptions[ OI_CHANGE_PASSWORD ].dwActuals == 0 )
  1778. {
  1779. // we need not do anything special here
  1780. }
  1781. // case 2
  1782. else if ( cmdOptions[ OI_CHANGE_PASSWORD ].pValue == NULL )
  1783. {
  1784. StringCopy( tchgsubops.szPassword, L"*", GetBufferSize(tchgsubops.szPassword)/sizeof(WCHAR));
  1785. }
  1786. // case 3
  1787. else if ( StringCompareEx( tchgsubops.szPassword, L"*", TRUE, 0 ) == 0 )
  1788. {
  1789. if ( ReallocateMemory( (LPVOID*)&tchgsubops.szPassword,
  1790. MAX_STRING_LENGTH * sizeof( WCHAR ) ) == FALSE )
  1791. {
  1792. SaveLastError();
  1793. return EXIT_FAILURE;
  1794. }
  1795. // ...
  1796. tchgoptvals.bNeedPassword = TRUE;
  1797. }
  1798. }
  1799. // validate start date
  1800. if ( 1 == cmdOptions[OI_CHANGE_STARTDATE].dwActuals)
  1801. {
  1802. // Validate Start Date value.
  1803. dwRetval = ValidateStartDate( tchgsubops.szStartDate, dwScheduleType,
  1804. cmdOptions[OI_CHANGE_STARTDATE].dwActuals,
  1805. bIsStDtCurDt);
  1806. if(EXIT_FAILURE == dwRetval )
  1807. {
  1808. return dwRetval; // Error in Day/Month string.
  1809. }
  1810. }
  1811. // validate end date
  1812. if ( 1 == cmdOptions[OI_CHANGE_ENDDATE].dwActuals )
  1813. {
  1814. // Validate End Date value.
  1815. dwRetval = ValidateEndDate( tchgsubops.szEndDate, dwScheduleType,
  1816. cmdOptions[OI_CHANGE_ENDDATE].dwActuals);
  1817. if(EXIT_FAILURE == dwRetval )
  1818. {
  1819. return dwRetval; // Error in Day/Month string.
  1820. }
  1821. }
  1822. //Check Whether end date should be greater than startdate
  1823. WORD wEndDay = 0;
  1824. WORD wEndMonth = 0;
  1825. WORD wEndYear = 0;
  1826. WORD wStartDay = 0;
  1827. WORD wStartMonth = 0;
  1828. WORD wStartYear = 0;
  1829. if( cmdOptions[OI_CHANGE_ENDDATE].dwActuals != 0 )
  1830. {
  1831. if( EXIT_FAILURE == GetDateFieldEntities( tchgsubops.szEndDate,&wEndDay,
  1832. &wEndMonth,&wEndYear))
  1833. {
  1834. return EXIT_FAILURE;
  1835. }
  1836. }
  1837. // get the date fields
  1838. if( ( cmdOptions[OI_CHANGE_STARTDATE].dwActuals != 0 ) &&
  1839. (EXIT_FAILURE == GetDateFieldEntities(tchgsubops.szStartDate,
  1840. &wStartDay,&wStartMonth,
  1841. &wStartYear)))
  1842. {
  1843. ShowMessage(stderr, GetResString(IDS_INVALID_STARTDATE) );
  1844. return EXIT_FAILURE;
  1845. }
  1846. // validate date format
  1847. if( (cmdOptions[OI_CHANGE_ENDDATE].dwActuals != 0) )
  1848. {
  1849. if( ( wEndYear == wStartYear ) )
  1850. {
  1851. // For same years if the end month is less than start month or for same years and same months
  1852. // if the endday is less than the startday.
  1853. if ( ( wEndMonth < wStartMonth ) || ( ( wEndMonth == wStartMonth ) && ( wEndDay < wStartDay ) ) )
  1854. {
  1855. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  1856. return EXIT_FAILURE;
  1857. }
  1858. }
  1859. else if ( wEndYear < wStartYear )
  1860. {
  1861. ShowMessage(stderr, GetResString(IDS_ENDATE_INVALID));
  1862. return EXIT_FAILURE;
  1863. }
  1864. }
  1865. // validate start time format
  1866. if (1 == cmdOptions[OI_CHANGE_STARTTIME].dwActuals)
  1867. {
  1868. // Validate Start Time value.
  1869. dwRetval = ValidateTimeString(tchgsubops.szStartTime);
  1870. if(EXIT_FAILURE == dwRetval)
  1871. {
  1872. // Error. Invalid date string.
  1873. ShowMessage(stderr,GetResString(IDS_INVALIDFORMAT_STARTTIME));
  1874. return dwRetval;
  1875. }
  1876. }
  1877. // validate end time format
  1878. if (1 == cmdOptions[OI_CHANGE_ENDTIME].dwActuals)
  1879. {
  1880. // Validate Start Time value.
  1881. dwRetval = ValidateTimeString(tchgsubops.szEndTime);
  1882. if(EXIT_FAILURE == dwRetval)
  1883. {
  1884. // Error. Invalid date string.
  1885. ShowMessage(stderr,GetResString(IDS_INVALIDFORMAT_ENDTIME));
  1886. return dwRetval;
  1887. }
  1888. }
  1889. return RETVAL_SUCCESS;
  1890. }
  1891. /******************************************************************************
  1892. Routine Description:
  1893. Release memory
  1894. Arguments:
  1895. [ in ] pParam : cmdOptions structure
  1896. Return Value :
  1897. TRUE on success
  1898. ******************************************************************************/
  1899. BOOL
  1900. ReleaseChangeMemory(
  1901. IN PTCHANGESUBOPTS pParams
  1902. )
  1903. {
  1904. // release memory
  1905. FreeMemory((LPVOID *) &pParams->szServer);
  1906. FreeMemory((LPVOID *) &pParams->szUserName);
  1907. FreeMemory((LPVOID *) &pParams->szPassword);
  1908. FreeMemory((LPVOID *) &pParams->szRunAsUserName);
  1909. FreeMemory((LPVOID *) &pParams->szRunAsPassword);
  1910. //reset all fields to 0
  1911. SecureZeroMemory( &pParams, sizeof( PTCHANGESUBOPTS ) );
  1912. return TRUE;
  1913. }