[CmdletBinding()]
Param(
   [string]$locationFTP
)

Write-host ""
Write-host ""

#Declaracao Variaveis
$disco=''

#Verifica qual disco esta as aplicacoes
IF(Test-Path C:\avls\AVLServicesIntrack.exe)
{
$disco='C:\avls'
}
ElseIf (Test-Path D:\avls\AVLServicesIntrack.exe)
{
$disco='D:\avls'
}
ElseIf (Test-Path E:\avls\AVLServicesIntrack.exe)
{
$disco='E:\avls'
}


#Stop GerenciadorServicosIntrack and replace status running to stop (1 -> 0)
Stop-Process -Name "GerenciadorServicosIntrack"

$gerenciador = "$disco\GerenciadorServicosIntrack.dat"

Stop-Process -Name "GerenciadorServicosIntrack"
$find = '=1'
$replace = '=0'
(Get-Content $gerenciador).replace($find, $replace) | Set-Content $gerenciador 

#Stop inlog services
Stop-Service CTVoicerTunelIntrack
Stop-Service CTVoicerDBClient 
Stop-Service CTVoicerServidorProcessos
Stop-Service CTVoicerDBDispositivos
Stop-Service CTVoicerAVLIntrack
Stop-Service CTVoicerCanIntrack
Stop-Service CTVoicerTecladoIntrack
Stop-Service CTVoicerDBDispositivosHistorico
Stop-Service GrupoInlogMinerador
Stop-Service frmServicoServidor #dbclientweb

Write-host "Aguardando encerramento dos servicos"

While ((Get-Process dbDispositivosServices -ErrorAction SilentlyContinue) -or (Get-Process dbDispositivosServicesHistorico -ErrorAction SilentlyContinue) -or (Get-Process ServidorProcessosServices -ErrorAction SilentlyContinue) -or (Get-Process dbClientServices -ErrorAction SilentlyContinue) -or (Get-Process AVLServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process TecladoServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process CanServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process RFIDServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process SerialServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process MifareServicesIntrack -ErrorAction SilentlyContinue) -or (Get-Process  TunelServicesIntrack -ErrorAction SilentlyContinue)-or (Get-Process DBClientWeb -ErrorAction SilentlyContinue))
{
 Write-host  "Servicos em execucao"
 Start-Sleep -Seconds 5
}
Write-host "SERVICOS PARADOS!" 
Start-Sleep -Seconds 1

Copy-Item -Path $locationFTP\*.exe -Destination  $disco -Force
Copy-Item -Path $locationFTP\RepositorioClient\*.exe -Destination  $disco\RepositorioClient\ -Force
Copy-Item -Path $locationFTP\Tunel\*.exe -Destination  $disco\Tunel\ -Force

Start-Process "$disco\GerenciadorServicosIntrack.exe" -Verb RunAs