Вот код PowerShell (можно использовать WMI, например, в бат-файле или собственном js-скрипте)
Код:
function Start-ProcessTree([string]$FilePath = $(Read-Host "Supply a value for the FilePath parameter"),[string]$ArgumentList,[int]$TimeoutMin = 60,[switch]$WaitForChildProcesses)
{
$Timeoutms = $TimeoutMin * 60 * 1000
$ProcessStartInfo = New-Object System.Diagnostics.ProcessStartInfo $FilePath
if ($ArgumentList) { $ProcessStartInfo.Arguments = $ArgumentList }
$Process = [System.Diagnostics.Process]::Start($ProcessStartInfo)
$ProcessId = $Process.Id
$ProcessStartTime = $Process.StartTime
$ProcessCompleted = $Process.WaitForExit($Timeoutms)
while ($WaitForChildProcesses -and $ProcessCompleted)
{
[array]$ChildProcesses = Get-WmiObject Win32_Process -Filter "ParentProcessId = $ProcessId"
if (!$ChildProcesses.Count)
{
break
}
$Elapsedms = (New-TimeSpan $ProcessStartTime (Get-Date)).TotalMilliseconds
if ($Elapsedms -lt $Timeoutms)
{
Start-Sleep -Seconds 1
}
else
{
$ProcessCompleted = $false
}
}
return $ProcessCompleted
}
Вызов делается так (стартуем общий стартер 1С и ждем завершения подчиненных процессов
Код:
# Указываем путь к 1С и проверяем наличие.
$str1CPath='C:\Program Files (x86)\1cv82\common\1cestart.exe'
if (!(Test-Path $str1CPath)) { "1C is missing at $str1CPath" ; exit 13 }
# Starting with default timeout 60 minutes
$Finished = Start-ProcessTree $str1CPath $arguments1C -WaitForChildProcesses
$EndDate = Get-Date -uFormat %Y-%m-%d
$EndTime = Get-Date -uFormat %H:%M:%S
if ($Finished)
{
"Success. Job finished $EndDate at $EndTime" | Write-LogFile $strLogName
}
else
{
"Error. Job stopped by timeout $EndDate at $EndTime" | Write-LogFile $strLogName
exit 10
}