OVH Cloud OVH Cloud

Programmer des taches planifiées

3 réponses
Avatar
Hervé
Bonjour,

J'aimerais programmer en vb des taches planifi=E9es. Y a t-
il une api qui le permet ?
O=F9 pourrais je trouver de l'aide ?

Merci pour vos r=E9ponses.
Herv=E9

3 réponses

Avatar
Axel Guerrier [MS]
Bonjour Hervé,

regarde du côté de NetScheduleJobAdd...

voici un morceau de code (non testé):

1. Create a new Standard EXE project. Form1 is created by default.

2. Add a command button to Form1.

3. Paste the following code into the code window of Form1:





Option Explicit


Private Declare Function NetScheduleJobAdd Lib "netapi32.dll" ( _

ByVal servername As String, _

bufPtr As Any, _

JobID As Long) _

As Long





Private Declare Function NetApiBufferFree Lib "netapi32.dll" ( _

bufPtr As Any) _

As Long





Private Declare Sub CopyToMemory Lib "kernel32" Alias "RtlMoveMemory" ( _

ByVal hpvDest As Long, _

ByVal hpvSource As String, _

ByVal cbCopy As Long)





Private Declare Function GlobalAlloc Lib "kernel32" ( _

ByVal Flags As Long, _

ByVal numBytes As Long) _

As Long


Private Declare Function GlobalFree Lib "kernel32" ( _

hMem) _

As Long





Private Const GMEM_ZEROINIT = &H40

Private Const GMEM_FIXED = &H0

Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)





Private Type AT_INFO

JobTime As Long

DaysOfMonth As Long

DaysOfWeek As Integer

Flags As Integer

Command As Long

End Type









Private Sub Command1_Click()

Dim exTime As Double

Dim atInfo As AT_INFO

Dim szCommand As String

Dim res As Long

Dim NewJobID As Long

Dim tmpCmd As String

Dim ref As Long


exTime = TimeValue("11:30 AM")

szCommand = "Notepad.exe"

'Change the time to milleseconds

atInfo.JobTime = exTime * 24 * 60 * 60 * 1000

atInfo.Command = GlobalAlloc(GPTR, Len(szCommand) * 3) + 2

tmpCmd = StrConv(szCommand, 64)

CopyToMemory atInfo.Command, tmpCmd, Len(tmpCmd)

res = NetScheduleJobAdd(vbNullString, atInfo, NewJobID)

If res <> 0 Then

MsgBox res

Else

MsgBox NewJobID

End If

res = GlobalFree(atInfo.Command)

End Sub





4. Run the sample.

5. Click the Command Button.





RESULT: You should get a message box with the Job ID assigned to the
scheduled

task or the error number if an error occured. In this case, NOTEPAD.EXE

should be scheduled to run the next time 11:30 AM occurs.


--
Axel GUERRIER
Microsoft France
--------------------
Merci de bien vouloir répondre à ce message dans le newsgroup où il a été
posté. Je le consulte régulièrement.

"Hervé" wrote in message
news:0ae401c38f04$fc6deed0$
Bonjour,

J'aimerais programmer en vb des taches planifiées. Y a t-
il une api qui le permet ?
Où pourrais je trouver de l'aide ?

Merci pour vos réponses.
Hervé
Avatar
Christophe QUEVAL
Avec la commande Windows "AT" ?

"Hervé" a écrit dans le message de
news:0ae401c38f04$fc6deed0$
Bonjour,

J'aimerais programmer en vb des taches planifiées. Y a t-
il une api qui le permet ?
Où pourrais je trouver de l'aide ?

Merci pour vos réponses.
Hervé
Avatar
Hervé
Merci pour la réponse.
Ca semble fonctionner comme je veux. super !

Hervé