Re: Agir sur le planificateur de tâches XP |
Sujet: Re: Agir sur le planificateur de tâches XP par xofxon sur 25/3/2005 13:45:32 Bonjour, ci-après le code, qui fonctionne chez moi (WXP Fam) en wd8. -- global vf_c_NameSpace est une chaine = "\root\cimv2" LOCAL vl_c_command est une chaîne vl_c_StartTime est une chaîne vl_b_RunRepeatedly est un booléen vl_e_DaysOfWeek est un entier vl_e_DaysOfMonth est un entier vl_b_InteractWithDesktop est un booléen // Sablier(Vrai) vl_c_command = "Calc.exe" vl_c_StartTime = "********214000.000000-000" vl_b_RunRepeatedly = Vrai SI PAS vl_b_RunRepeatedly ALORS vl_e_DaysOfWeek = 0 SINON vl_e_DaysOfWeek = 1+2 FIN vl_e_DaysOfMonth = 1+2+4+8 vl_b_InteractWithDesktop = Vrai pf_Ajoute_Tache(vl_c_command,vl_c_StartTime,vl_b_RunRepeatedly,vl_e_DaysOfWeek,vl_e_DaysOfMonth,vl_b_InteractWithDesktop) Sablier(Faux) PROCEDURE pf_Ajoute_Tache(vv_c_Command,vv_c_StartTime,vv_b_RunRepeatedly,vv_e_DaysOfWeek,vv_e_DaysOfMonth,vv_b_InteractWithDesktop) // Infos sur http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/create_method_in_class_win32_scheduledjob.asp LOCAL ol_oad_objLocator est un objet Automation dynamique ol_oad_objService est un objet Automation dynamique ol_oad_objInstance est un objet Automation dynamique vl_v_errJobCreated est un Variant // retour info sur création de tâche vl_v_JobId est un Variant // identifiant de la tâche (en retour) // ol_oad_objLocator = allouer un objet Automation "WbemScripting.SWbemLocator" SI ol_oad_objLocator=Null ALORS Erreur(ErreurInfo()) GOTO Desallocation FIN ol_oad_objService=ol_oad_objLocator>>ConnectServer(".", vf_c_NameSpace, Null, Null) SI ol_oad_objService=Null ALORS Erreur(ErreurInfo()) GOTO Desallocation FIN //ol_oad_objService>>Security_>>ImpersonationLevel =3 ol_oad_objInstance=ol_oad_objService>>Get("Win32_ScheduledJob") SI ol_oad_objInstance=Null ALORS Erreur(ErreurInfo()) GOTO Desallocation FIN vl_v_errJobCreated= ol_oad_objInstance>>Create(vv_c_Command ,vv_c_StartTime ,vv_b_RunRepeatedly, vv_e_DaysOfWeek,vv_e_DaysOfMonth ,vv_b_InteractWithDesktop, vl_v_JobId) //Return code Description //0 The request is accepted. //1 The request is not supported. //2 The user does not have the necessary access. //8 Interactive Process. //9 The directory path to the service executable file cannot be found. //21 Invalid parameters have been passed to the service. //22 The account that this service runs under is invalid or lacks the permissions to run the service. SELON vl_v_errJobCreated CAS 0 //The request is accepted. CAS 1 //The request is not supported. CAS 2 //The user does not have the necessary access. CAS 8 //Interactive Process. CAS 9 //The directory path to the service executable file cannot be found. CAS 21 //Invalid parameters have been passed to the service. CAS 22 //The account that this service runs under is invalid or lacks the permissions to run the service. AUTRE CAS // Cas pas décrit par microsoft au 23 mars 2005 FIN Desallocation: // Libérer les camarades SI ol_oad_objLocator<>Null ALORS libérer(ol_oad_objLocator) SI ol_oad_objService<>Null ALORS libérer(ol_oad_objService) SI ol_oad_objInstance<>Null ALORS libérer(ol_oad_objInstance) |