Can I be sure that xcopy.exe exists in every Windows system (7+) and that it can always be found in the system PATH (e.g. C:\windows\system32)?
2 Answers
This Powershell script (needs to be run as admin) can be used to check for the presence of xcopy and copy it from a network server if not present; if path doesn't exist, it will create it as well.
$xcopypath = 'C:\Windows\System32\xcopy.exe' $xcopy = Test-Path $xcopypath $server = \\NAS\xcopy.exe $envpath = Get-ChildItem Env: $path = $envpath.Value if($xcopy){ write-host -ForegroundColor Green "xCopy present" }while($xcopy -ne 'True'){ write-host -ForegroundColor red "xCopy not present" Copy-Item $server -path C:\Windows\System32 $xcopy = Test-Path C:\Windows\System32\xcopy.exe } if($path.Contains('C:\Windows\system32\xcopy.exe')){ write-host -ForegroundColor Green "Path exists" }else{ write-host -ForegroundColor Yellow 'Path does not exist. Creating path' [Environment]::SetEnvironmentVariable("xCopy.exe", "$xcopypath", "Machine") } 1Yes, it exists in pretty much every windows, not sure about win 95 and 98 but in the otheres it is all present.
0