Salut,
Nous avons sur notre campus plus de 400 machines. Et nous voulons faire en sorte que les machines s'éteignent automatiquement tous les soirs vers par exemple, 23h00.
Nous voulons faire avec un VBScript qui créé un plannificateur de tâche.
Le script fonctionne bien, c'est à dire qu'il créé la tâche mais ne s'applique pas.
Si je regarde les options de la tâche créé, il faut préciser un user name et mot de passe admin pour que la tâche fonctionne. Mais je ne sais pas comment l'intégrer au script.
Voici le script:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: ScheduleShutdown.vbs
'
' AUTHOR: IS Department , IMD
' DATE : 13/09/2006
'
' COMMENT: Schedules a daily shutdown of the computer everyday at 15:00
'
'==========================================================================
strComputer = "."
strOldCommand="shutdown.exe -s -t 00"
strNewCommand=strOldCommand
'Checks if the schedule has already been scheduled
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery("Select * from Win32_ScheduledJob")
For Each objJob in colScheduledJobs
if objJob.Command=strOldCommand Then
AlreadyScheduled = True
end If
Next
'If it has not been already scheduled, then schedule it
if not AlreadyScheduled Then
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
JobID = "DailyShutdown"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreate = objNewJob.Create _
(strNewCommand, "********150000.000000+120", _
True , _
1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64, _
, _
False, _
JobId)
If not errJobCreate = 0 Then
WScript.Echo "Job not created. Error code = " & errJobCreate
Else
wscript.echo "Scheduled Task created successfully."
End If
Else
wscript.echo "No need to create task"
End If
Merci d'avance pour votre aide,
Nicolas