Hi there,
I want to add a script within app-v to edit the services file, this is because you can't virtualize the services file. I tested the script and it works just fine, this scripts needs to be run in machine context so it is executed when the package is added the first time (add-appvclientpackage). However when you remove the appv package the services file still has the entries in it. You can also make a .ps1 script which executes when the package is removed, but i'm not very keen on this method. It doesn't need to remove the records because packages are only removed when something is wrong with them. Now i've build this script which will execute during adding the package for the first time (add-appvclientpackage):
$sap = Select-String -Pattern "sapmsrp" -Path C:\Windows\System32\drivers\etc\services
if ($sap -match 'sapmsrp15') {Write-Host "do nothing"}
else {ac -Encoding UTF8 -path C:\Windows\System32\drivers\etc\services "sapmsrp15`t 3613/tcp`t`t`t #SAP System Message Server Port`r`nsapmsrp15`t 3654/tcp`t`t`t #SAP System Message Server Port"}
What it does it checks if there is a string in the services file containing sapmsrp15 if it doesn't contain this string it adds the records to the services file. Because it's a unique string I think it's pretty ok to do it this way but if you got any tips for me you are welcome. Just checking if this is the right way to do it, I don't know a way to clear lines in a file.