'--------------------------------------------------------- ' This script create a schedueld task to start on event 'Universe started'. ' start uv.exe UV.COLDSTART (UV/VOC UV.COLDSTART a PA to start phantoms) '--------------------------------------------------------- '******************************************************** Dim oShell Set oShell = CreateObject("WScript.Shell") '******************************************************** ' constant taskAuthor = oShell.ExpandEnvironmentStrings( "%USERNAME%" ) taskRunAsUser = "USER" taskArgument = "UV.COLDSTART" '******************************************************** ' get the uvadm passwd taskRunAsPasswd = Inputbox("Please enter the uvadm password:","passwd") '******************************************************** ' read uv registry value uvhome Dim UvHome on error resume next err.clear ' try 32 bit UvHome = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Rocket Software\UniVerse\CurrentVersion\UvHome") if err then ' try 64bit err.clear UvHome = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Rocket Software\UniVerse\CurrentVersion\UvHome") if err then ' no uvhome msgbox "uvhome non défini en registry HKLM\software\ {Wow6432Node\} Rocket Software\UniVerse\CurrentVersion\UvHome" wscript.Quit end if end if ' teste le directory trouvé ' if dir(UvHome) = "" then ' msgbox "path uvhome invalide : " & UvHome ' wscript.Quit ' end if '******************************************************** ' A constant that specifies an event trigger. ' https://docs.microsoft.com/en-us/windows/desktop/taskschd/trigger const TriggerTypeEvent = 0 '******************************************************** ' A constant that specifies an execute shell action. ' https://docs.microsoft.com/en-us/windows/desktop/TaskSchd/actioncollection-create const ActionTypeExec = 0 '******************************************************** ' Create the TaskService object. Set service = CreateObject("Schedule.Service") call service.Connect() '******************************************************** ' Get a folder to create a task definition in. Dim rootFolder Set rootFolder = service.GetFolder("\") ' The taskDefinition variable is the TaskDefinition object. ' The flags parameter is 0 because it is not supported. Dim taskDefinition Set taskDefinition = service.NewTask(0) '******************************************************** ' Define information about the task. ' Set the registration info for the task by ' creating the RegistrationInfo object. Dim regInfo Set regInfo = taskDefinition.RegistrationInfo regInfo.Description = "Start on uvhome uv.exe UV.COLDSTART PAragraph" regInfo.Author = taskAuthor '******************************************************** ' Set the task setting info for the Task Scheduler by ' creating a TaskSettings object. Dim settings Set settings = taskDefinition.Settings settings.StartWhenAvailable = True '******************************************************** ' Create an event trigger. Dim triggers Set triggers = taskDefinition.Triggers Dim trigger Set trigger = triggers.Create(TriggerTypeEvent) ' Trigger variables that define when the trigger is active. trigger.Id = "OnUniverseStarted" trigger.StartBoundary = "2018-01-12T12:00:00" trigger.EndBoundary = "2500-01-12T12:00:00" trigger.ExecutionTimeLimit = "PT10M" '10 MINUTES trigger.Delay = "PT10S" ' 10 seconds delay between task and action to be sure uv is started ' Define the event query. The trigger will start the task when an event is received. trigger.Subscription = "<QueryList> " & _ "<Query Id='1'> " & _ "<Select Path='UniVerse'>*[EventData[Data='UniVerse (log daemon) started']]</Select>" & _ "</Query></QueryList>" '*********************************************************** ' Create the action for the task to execute. ' Add an action to the task. The action sends an email message. Dim Action ' action execute a process Set Action = taskDefinition.Actions.Create( ActionTypeExec ) Action.Path = Uvhome & "\bin\uv.exe" Action.Arguments = taskArgument Action.WorkingDirectory = UvHome '*********************************************************** WScript.Echo "Task definition ready. <enter> will register." call rootFolder.RegisterTaskDefinition( "Universe Coldstart after UV Started", taskDefinition, 6, taskRunAsUser , taskRunAsPasswd , 1) WScript.Echo "Universe Coldstart - Task registered."
La raison est que si on reste en priorité “7” (Low), Windows peut décider de bloquer certains accès fichiers des lignes WI.HDL si l'accès aux fichiers est fortement utilisé.
Une alternative consiste à utiliser Powershell :
# vérifie que la tâche n'existe pas if (Get-ScheduledTask -taskname 'uv.coldstart' -ErrorAction Ignore) { write-error 'taskname uv.port.status.cache exist !' exit 1 } # crée l'action $Action = New-ScheduledTaskAction -Execute "$($env:UVDB)\uv\bin\uv.exe" -Argument '"UV.COLDSTART"' -WorkingDirectory "$($env:UVDB)\UV" # crée le trigger, on event $Trigger = ((cimclass MSFT_TaskEventTrigger root/Microsoft/Windows/TaskScheduler) | New-CimInstance -ClientOnly) $Trigger.Enabled = $true $Trigger.Subscription = '<QueryList><Query Id="0" Path="UniVerse"><Select Path="UniVerse">*[EventData[Data="UniVerse (log daemon) started"]]</Select></Query></QueryList>' # crée un déclencheur pour un délai de 10 secondes $DelayTrigger = New-ScheduledTaskTrigger -Once -At ((Get-Date).AddSeconds(10)) $DelayTrigger.StartBoundary = ((Get-Date).AddSeconds(10)).ToString("yyyy-MM-ddTHH:mm:ss") # fixe les settings $Settings = New-ScheduledTaskSettingsSet $Settings.Enabled = $True $Settings.Priority = 4 # crée la tâche $Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings $Task.Author = "$($env:USERDOMAIN)\$($env:USERNAME)" $Task.Date = (GET-DATE) $Task.Description = "start uv.coldstart at uv boot" # enregistre la tâche try { Register-ScheduledTask -TaskName 'uv.coldstart' -InputObject $Task -User (Read-Host 'What is the username to run the task uv.port.status.refresh domain\userid?') -Password $([Runtime.InteropServices.Marshal]::PtrToStringAuto( [Runtime.InteropServices.Marshal]::SecureStringToBSTR((Read-Host 'What is the password?' -AsSecureString))) ) } catch { $_ exit 1 }