Skip to content

Instantly share code, notes, and snippets.

@vannmangel
Last active January 14, 2021 11:54
Show Gist options
  • Save vannmangel/0e0ff4aeba663159bcb8 to your computer and use it in GitHub Desktop.
Save vannmangel/0e0ff4aeba663159bcb8 to your computer and use it in GitHub Desktop.
Remove ads in skype
# start as admin!
# prompt for username
$SkypeUserName = Read-Host -Prompt "What is your Skype username?"
# stop skype-process
try{
if(Get-Process | ? {$_.Name -like 'skype'}) {Stop-Process -Name skype}
# commit changes to hosts file
$hostfile = "C:\Windows\System32\Drivers\etc\hosts"
if ((gc $hostfile) -notcontains "127.0.0.1 g.msn.com"){
Write-Host -ForegroundColor Green "Adding content to hosts file"
Add-Content $hostfile `
"`r`n127.0.0.1 rad.msn.com
`r`n127.0.0.1 live.rads.msn.com
`r`n127.0.0.1 ads1.msn.com
`r`n127.0.0.1 tatic.2mdn.net
`r`n127.0.0.1 g.msn.com
`r`n127.0.0.1 a.ads2.msads.net
`r`n127.0.0.1 bads2.msads.net
`r`n127.0.0.1 ac3.msn.com" `
-Force
} else {
Write-Host -ForegroundColor Red "Your hosts-file most likely contains the correct values for redirecting URI for Ads to Localhost."
}
# set var for xml path
$xmlpath = "C:\users\$env:USERNAME\Appdata\Roaming\skype\$SkypeUserName\config.xml"
# check if xml is read only, set to false if value is true
if (Get-ItemProperty -Path $xmlpath | ? {$_.IsReadOnly -eq $true}) {
Set-ItemProperty -Path $xmlpath -Name IsReadOnly -Value $false}
# commit changes to xml file
Write-Host -ForegroundColor Green "Setting AdvertPlaceholder and AdvertEastRailsEnabled to 0"
$xml = [xml] (Get-Content $xmlpath)
$xml.config.UI.General.AdvertPlaceholder = '0'
$xml.config.UI.General.AdvertEastRailsEnabled = '0'
$xml.Save($xmlpath)
# set xml to read only
Set-ItemProperty -Path $xmlpath -Name IsReadOnly -Value $true
}
catch {
write-host -ForegroundColor Red "There was some kind of error in here, I would suggest that you make sure you run this script as administrator or change your hosts file and config.xml manually."
exit
}
finally {
try{
$answer = Read-Host "Start Skype and tell me if your ad ribbon is removed! Yes/No (Do NOT close this window before you've tried.)"
if ($answer -eq 'N' -or $answer -eq 'No'){
# set var
$xmlbackup = "C:\users\$env:USERNAME\appdata\roaming\skype\$SkypeUserName\config.xml_old"
$skypedir = "C:\users\$env:USERNAME\appdata\roaming\skype\$SkypeUserName"
#kill process if exist
Write-Host -ForegroundColor Green "Killing skype.exe"
if(Get-Process | ? {$_.Name -like 'skype'}) {
Stop-Process -Name skype}
# backing up config xml
Write-Host -ForegroundColor Green "Backing up your config.xml file"
Copy-Item -Path $xmlpath -Destination $xmlbackup -Force
# removing read only
if (Get-ItemProperty -Path $xmlpath | ? {$_.IsReadOnly -eq $true}) {
Set-ItemProperty -Path $xmlpath -Name IsReadOnly -Value $false}
# fetch the backup file and remove the content - then save as new config.xml
Write-Host -ForegroundColor Green "Fetching the backup file, removing some content, then saving as a new config.xml"
Rename-Item $xmlpath -NewName $skypedir\config_old.xml -Force
gc $xmlbackup| ? {$_ -notmatch "Advert*"} | Out-File $xmlpath
Set-ItemProperty -Path $xmlpath -Name IsReadOnly -Value $true
Write-Host -ForegroundColor Green "Let's hope the ribbons are gone. If they're not, I don't think there's much more I can do. Give it a go :-)"
} else {
Write-Host -ForegroundColor Green "Bye :-)"
Exit
}
} catch {
write-host -ForegroundColor Red "If I was you, I'd remove all that stuff manually. This script is clearly not made for your computer :-P"
exit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment