Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
disable_skype_ads
@echo off
TITLE DISABLE SKYPE ADS
:: ================================== LICENSE ==================================
:: Copyright (C) 2015 Anthony Gaudino
:: This program is free software: you can redistribute it and/or modify it under
:: the terms of the GNU General Public License as published by the Free Software
:: Foundation, either version 3 of the License, or (at your option) any later
:: version.
:: This program is distributed in the hope that it will be useful, but WITHOUT
:: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
:: FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
:: details.
:: You should have received a copy of the GNU General Public License along with
:: this program. If not, see <http://www.gnu.org/licenses/>.
:: =================================== ABOUT ===================================
:: Please read the HELP section at end of this file or run the script with the
:: /help argument to read how it works.
:: ================================ SOURCE CODE ================================
PUSHD "%~dp0"
SETLOCAL
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
:: --------------------------------- CONSTANTS ---------------------------------
:: There is no way to define constants in Batch, so we consider all variables
:: bellow as constants and use the %_CONST_NAME_% syntax.
SET "_THIS_SCRIPT_NAME_=%0"
:: Parameters names
SET "_PARAM_HELP_=/help"
SET "_PARAM_INTERACTIVE_=/interactive"
SET "_PARAM_ADD_HOSTS_=/addHosts"
SET "_PARAM_SKYPE_USERS_=skypeUsers"
:: Paths
SET "_HOSTS_DIR_PATH_=%SYSTEMROOT%\System32\drivers\etc"
SET "_HOSTS_FILE_PATH_=%_HOSTS_DIR_PATH_%\hosts"
SET "_HOSTNAMES_LIST_FILE_NAME_=hostnames.txt"
SET "_SKYPE_SETTINGS_DIR_PATH_=%APPDATA%\Skype"
SET "_SKYPE_USER_SETTINGS_FILE_NAME_=config.xml"
:: Skype parameter strings
SET "_SKYPE_PARAM_FIND_=<AdvertPlaceholder>1</AdvertPlaceholder>"
SET "_SKYPE_PARAM_SET_=<AdvertPlaceholder>0</AdvertPlaceholder>"
:: --------------------------------- VARIABLES ---------------------------------
:: For variables we use the !_var_name_! syntax.
SET "_argument_="
:: Parameters values
SET "_interactive_=false"
SET "_add_hosts_=false"
SET "_skype_usernames_="
:: Paths
SET "_skype_user_settings_file_path_="
SET "_skype_user_settings_dir_path_="
:: Success, errors and warnings flags
SET "_success_add_hosts_=false"
SET "_success_set_skype_settings_=false"
SET "_error_hosts_file_not_found_=false"
SET "_error_access_denied_hosts_=false"
SET "_error_invalid_argument_=false"
:: Interactive session choice
SET "_choice_=false"
:: ------------------- CHECK ARGUMENTS AND CALL SUBROUTINES --------------------
:: Default behaviour for no arguments
IF "%~1" == "" (
GOTO:help
)
:: Iterate through all arguments
:: /help have precedence over other arguments, except /interactive and invalid
:: arguments
:getArgument
SET "_argument_=%~1"
IF "!_argument_!" NEQ "" (
IF /I "%~1" == "%_PARAM_HELP_%" (
GOTO:help
) ELSE (
IF /I "%~1" == "%_PARAM_INTERACTIVE_%" (
CALL:interactiveSession
IF /I "!_choice_!" == "EXIT" GOTO:exitSuccess
) ELSE (
IF /I "%~1" == "%_PARAM_ADD_HOSTS_%" (
SET "_add_hosts_=true"
) ELSE (
IF /I NOT "!_argument_!" == "!_argument_:%_PARAM_SKYPE_USERS_%=!" (
:: Get list of Skype users
SET "%~1"
SET "_skype_usernames_=!%_PARAM_SKYPE_USERS_%!"
) ELSE (
SET "_error_invalid_argument_=true"
CALL:showMessage
GOTO:exitFail
))))
SHIFT
GOTO:getArgument
)
IF /I "!_add_hosts_!" == "true" CALL:addHosts
IF /I NOT "!_skype_usernames_!" == "" CALL:setSkypeParameter
:: After doing everything requested by user, show messages and exit
CALL:showMessage
GOTO:exitSuccess
:: -------------------------------- SUBROUTINES --------------------------------
:: =================
:: interactiveSession
:: =================
::
:: Start an interactive session where user can answer questions to set
:: parameters.
::
:interactiveSession
ECHO.
ECHO ========================== %_THIS_SCRIPT_NAME_% ===========================
ECHO.
ECHO ===== SET BLACKLIST =====
ECHO.
ECHO Add a blacklist of ADS servers domains from file hostnames.txt to Windows
ECHO hosts file, this will block Skype access to ADS servers.
ECHO.
ECHO This will hide all ADS in Skype, but Skype won't show the "Skype Home"
ECHO anymore.
ECHO.
ECHO.
:: Get answer
SET /P _choice_=Add a blacklist? [Y/N]
IF /I "!_choice_!" == "Y" (
SET "_add_hosts_=true"
) ELSE (
SET "_add_hosts_=false"
)
ECHO.
ECHO.
ECHO.
ECHO ===== CHANGE SKYPE USER SETTINGS FILE =====
ECHO.
ECHO Change a parameter in Skype user settings file.
ECHO.
ECHO This will hide the ADS block that appears in the right side of chat but the
ECHO Skype settings file will become read only, and any changes made in Skype UI
ECHO settings will be lost after exiting Skype. This doesn't affect Skype
ECHO contacts as they are saved in Skype server.
ECHO.
ECHO This only apply to Skype users available for the current Windows user.
ECHO.
ECHO.
ECHO Please type * to change settings file of all available Skype users or write
ECHO the Skype usernames separated by a comma. Please don't enter whitespace
ECHO between names. CORRECT INPUT EXAMPLE: todd,jack1234,bill_gaytes
ECHO Left blank to NOT change any Skype user settings files.
ECHO.
:: Get usernames
SET /P _skype_usernames_=Usernames: [*/LIST OF USERNAMES]
ECHO.
ECHO.
ECHO.
:: Ask for confirmation
IF /I "!_add_hosts_!" == "true" (
ECHO ADD HOSTS: YES
) ELSE (
ECHO ADD HOSTS: NO
)
ECHO SKYPE USERNAMES: !_skype_usernames_!
ECHO.
ECHO.
SET /P _choice_=Continue? [Y/N]
:: Set to exit if no confirmation or if user sets none of the parameters
IF /I NOT "!_choice_!" == "Y" (
SET "_choice_=EXIT"
ECHO.
ECHO.
ECHO EXITING NOW
ECHO.
ECHO.
GOTO:EOF
)
IF /I "!_add_hosts_!" == "false" (
IF /I "!_skype_usernames_!" == "" (
SET "_choice_=EXIT"
ECHO.
ECHO.
ECHO NO PARAMETERS WERE SET
ECHO.
ECHO EXITING NOW
ECHO.
ECHO.
GOTO:EOF
)
)
ECHO.
GOTO:EOF
:: =================
:: addHosts
:: =================
::
:: Adds hosts to Windows hosts file, if necessary.
::
:addHosts
:: Check if hosts already exists in hosts file
FIND /I "skype" "%_HOSTS_FILE_PATH_%" > nul 2>&1
IF !ERRORLEVEL! == 0 (
SET "_success_add_hosts_=true"
GOTO:EOF
)
:: Check if the file containing hosts list is available
IF NOT EXIST "%_HOSTNAMES_LIST_FILE_NAME_%" (
SET "_error_hosts_file_not_found_=true"
GOTO:EOF
)
:: Check if user has administrator privileges
MD "%_HOSTS_DIR_PATH_%\windowssucks" > nul 2>&1
IF NOT !ERRORLEVEL! == 0 (
SET "_error_access_denied_hosts_=true"
GOTO:EOF
)
RMDIR "%_HOSTS_DIR_PATH_%\windowssucks" > nul 2>&1
:: Add hosts to Windows hosts file
TYPE "hostnames.txt" >> "%_HOSTS_FILE_PATH_%"
SET "_success_add_hosts_=true"
GOTO:EOF
:: =================
:: setSkypeParameter
:: =================
::
:: Check the Skype usernames list and if they exists get it's settings file
:: path and call the setSkypeParameterOnFile subroutine to make changes to the
:: file
::
:setSkypeParameter
IF /I "!_skype_usernames_!" == "*" (
:: Search and change all config.xml files on Skype settings folder
FOR /R "%_SKYPE_SETTINGS_DIR_PATH_%" %%f IN ("%_SKYPE_USER_SETTINGS_FILE_NAME_%") DO (
IF EXIST "%%f" (
SET "_skype_user_settings_dir_path_=%%~pf"
SET "_skype_user_settings_file_path_=%%f"
CALL:setSkypeParameterOnFile
)
)
) ELSE (
:: Check if Skype user exists and if true change it's setting
FOR %%f IN (!_skype_usernames_!) DO (
IF EXIST "!_SKYPE_SETTINGS_DIR_PATH_!\%%f" (
SET "_skype_user_settings_dir_path_=%_SKYPE_SETTINGS_DIR_PATH_%\%%f"
SET "_skype_user_settings_file_path_=!_skype_user_settings_dir_path_!\%_SKYPE_USER_SETTINGS_FILE_NAME_%"
CALL:setSkypeParameterOnFile
)
)
)
SET "_success_set_skype_settings_=true"
GOTO:EOF
:: =================
:: setSkypeParameterOnFile
:: =================
::
:: Sets the parameter on Skype user settings file to remove the ADS block and
:: locks the file by setting a read-only attribute.
::
:setSkypeParameterOnFile
:: Check if file already has the parameter set to 0
FIND /I "%_SKYPE_PARAM_SET_%" "!_skype_user_settings_file_path_!" > nul 2>&1
IF !ERRORLEVEL! == 0 (
:: Make sure file is locked for Skype anyway
ATTRIB +R "!_skype_user_settings_file_path_!" > nul 2>&1
GOTO:EOF
)
:: Remove read only attribute from settings file
ATTRIB -R "!_skype_user_settings_file_path_!" > nul 2>&1
:: Delete temp file if it exists
IF EXIST "!_skype_user_settings_file_path_!_new" (
DEL /F /Q "!_skype_user_settings_file_path_!_new" > nul 2>&1
)
:: Sets Skype parameter on user settings file
FOR /F "tokens=1,* delims=]" %%A IN ('"TYPE "!_skype_user_settings_file_path_!"|FIND /n /v """') DO (
SET "line=%%B"
IF DEFINED line (
SET "line=!line:%_SKYPE_PARAM_FIND_%=%_SKYPE_PARAM_SET_%!"
ECHO(!line!>>"!_skype_user_settings_file_path_!_new"
)
)
MOVE /Y "!_skype_user_settings_file_path_!_new" "!_skype_user_settings_file_path_!" > nul 2>&1
:: ADD read only attribute, so Skype wont mess with it
ATTRIB +R "!_skype_user_settings_file_path_!" > nul 2>&1
GOTO:EOF
:: =================
:: showMessage
:: =================
::
:: Shows a message.
::
:showMessage
ECHO.
ECHO === %_THIS_SCRIPT_NAME_% ===
ECHO.
IF /I "!_error_invalid_argument_!" == "true" (
ECHO.
ECHO ERROR: Invalid argument: "%_argument_%"
ECHO Run %_THIS_SCRIPT_NAME_% %_PARAM_HELP_% for usage
ECHO.
)
IF /I "!_error_hosts_file_not_found_!" == "true" (
ECHO.
ECHO ERROR: Could not find hostnames.txt.
ECHO.
)
IF /I "!_error_access_denied_hosts_!" == "true" (
ECHO.
ECHO ERROR: Access denied to Windows hosts file.
ECHO Please, run again as Administrator.
ECHO.
)
IF /I "!_success_add_hosts_!" == "true" (
ECHO.
ECHO SUCCESS: Blacklist added to Windows hosts file.
ECHO.
)
IF /I "!_success_set_skype_settings_!" == "true" (
ECHO.
ECHO SUCCESS: Skype settings files changed.
ECHO.
)
ECHO.
ECHO === %_THIS_SCRIPT_NAME_% ===
ECHO.
GOTO:EOF
:: ------------------------------- HELP MESSAGE --------------------------------
:help
ECHO.
ECHO.
ECHO NAME
ECHO %_THIS_SCRIPT_NAME_% - Disable Skype Advertisements.
ECHO.
ECHO AUTHOR AND LICENSE
ECHO Anthony Gaudino GPL V3
ECHO.
ECHO SYNOPSIS
ECHO %_THIS_SCRIPT_NAME_% [%_PARAM_HELP_%] [%_PARAM_ADD_HOSTS_%]
ECHO {["%_PARAM_SKYPE_USERS_%=*"] ^|
ECHO ["%_PARAM_SKYPE_USERS_%=userName1,userName2..."]}
ECHO.
ECHO DESCRIPTION
ECHO This Windows batch script can disable ADS from Skype 7+ by doing the
ECHO following:
ECHO.
ECHO 1. Adding a blacklist of ADS servers domains from file hostnames.txt to
ECHO Windows hosts file, this will block Skype access to ADS servers.
ECHO.
ECHO 2. Hide the chat ADS block that still appears even with the addition of
ECHO blacklists in hosts file as stated above.
ECHO This is done by changing a parameter in Skype user settings file and
ECHO blocking Skype access to this file by setting a read only attribute
ECHO on it.
ECHO This is only done for the current Windows User logged in.
ECHO You can specify the Skype usernames that will have their
ECHO configuration files changed.
ECHO.
ECHO Please note that this script needs administrator privileges to execute
ECHO all of it's functionalities.
ECHO.
ECHO You must restart Skype to changes to take effect. You can also restart
ECHO your computer just to make sure.
ECHO.
ECHO.
ECHO WARNING:
ECHO.
ECHO This script is meant to be run on Windows Vista, 7 or 8.
ECHO Currently it was only tested on Windows 8.1 64bit.
ECHO.
ECHO Currently only tested in Skype for desktop version 7.5.85.101.
ECHO.
ECHO When the blacklist of ADS servers is added to hosts file, Skype won't
ECHO be able to show the Skype Home anymore.
ECHO.
ECHO The Skype settings file will become read only, this means that changes
ECHO made in Skype UI settings will not be saved and will be lost after
ECHO exiting Skype.
ECHO This doesn't affect Skype contacts as they are saved in Skype server.
ECHO To be able to save settings again, the users need to remove the read
ECHO only attribute from their Skype settings.xml, note that doing so will
ECHO allow Skype to change the ADS block setting to on again.
ECHO.
ECHO.
ECHO THIS SCRIPT WON'T MAKE ANY BACKUP OF YOUR DATA.
ECHO.
ECHO OPTIONS
ECHO Options are NOT case sensitive, EX: /addHosts = /ADDhosts.
ECHO.
ECHO %_PARAM_HELP_%
ECHO Shows this help message.
ECHO.
ECHO %_PARAM_INTERACTIVE_%
ECHO Start an interactive session where user can answer questions to set
ECHO parameters.
ECHO.
ECHO %_PARAM_ADD_HOSTS_%
ECHO Adds a blacklist of ADS servers domains from hostnames.txt to
ECHO Windows hosts file.
ECHO.
ECHO "%_PARAM_SKYPE_USERS_%="
ECHO A list of Skype usernames that will have their settings files
ECHO changed.
ECHO Only users available to the current Windows user can/will be used.
ECHO This parameter must be enclosed in double quotes (""), after the
ECHO command name there must be an equal sign (=) and usernames must be
ECHO separated by commas, no blank spaces are allowed.
ECHO Use an asterisk (*) for all Skype users available.
ECHO.
ECHO EXAMPLES:
ECHO Change files of all available Skype users:
ECHO "%_PARAM_SKYPE_USERS_%=*"
ECHO Change files of Skype users todd, jack1234 and bill_gaytes:
ECHO "%_PARAM_SKYPE_USERS_%=todd,jack1234,bill_gaytes"
ECHO.
ECHO.
GOTO:exitSuccess
:: ----------------------------------- EXIT ------------------------------------
:exitSuccess
EXIT /B 0
:exitFail
EXIT /B 1
:: Script should never execute this
ECHO.
ECHO === %_THIS_SCRIPT_NAME_% ===
ECHO.
ECHO WARNING: Unexpected behaviour.
ECHO.
ECHO === %_THIS_SCRIPT_NAME_% ===
ECHO.
EXIT /B 1
@echo off
TITLE DISABLE SKYPE ADS
:: ---------------------------------- LICENSE ----------------------------------
:: Copyright (C) 2015 Anthony Gaudino
:: This program is free software: you can redistribute it and/or modify it under
:: the terms of the GNU General Public License as published by the Free Software
:: Foundation, either version 3 of the License, or (at your option) any later
:: version.
:: This program is distributed in the hope that it will be useful, but WITHOUT
:: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
:: FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
:: details.
:: You should have received a copy of the GNU General Public License along with
:: this program. If not, see <http://www.gnu.org/licenses/>.
:: =================================== ABOUT ===================================
:: Runs the disable_skype_ads.bat in interactive mode, so users can just
:: right-click and select Run as Administrator from this script.
:: ================================ SOURCE CODE ================================
PUSHD "%~dp0"
SETLOCAL
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
START "DISABLE SKYPE ADS" /B /WAIT "disable_skype_ads.bat" /interactive
PAUSE
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.