rem This script is to deploy the 3CX Windows Phone client to remote computers
rem and to copy the users configuration settings along with customized options
rem directly into the users AppData folder so when they launch 3CX, even for the
rem first time, they will already have all their settings and company customizations.
rem There are several pre-requesistes for this script to work properly and they are below.
rem 1. You must save a copy of the 3cxconfig file sent by the Welcome Email for each user.
rem This is the most time consuming, however 3CX does not offer another way to get these files.
rem 2. Once you have each users welcome email, you need to name them "username".3cxconfig where
rem "username" is the users domain name. Then copy the file to a network share.
rem 3. This script will only copy the proper 3cx config files to a users AppData folder if both exist.
rem That means the user must have already logged into the remote pc at some point in the past and
rem you must have saved the 3cconfig file from the welcome email to the network path.
rem 4. You may be able to break this up, however I have most of it as one long task so that it will only
rem countinue if the previous commands were succesful. Preventing it from copying files or attempting to
rem do things that are not needed.
rem 5. The powershell script is a seperate file and is used to modify all users configus with custom settings
rem that you want company wide. For example having a company logo, brining chat notifications to the front, etc.
rem You do not need to use it if you want to stick with the default 3cx settings.
rem 6. You will need to make your own CompanyLogo HeaderImage.jpg and place it in the share path you are using to have it replaced.
rem
rem The basic steps of the script are in this order:
rem 1. Kill the 3CX processes running on the remote machine to allow overwriting any current 3cx config files.
rem 2. Goto the C:\users folder.
rem 3. Make a users.txt file in C:\temp containg a list of all the user folders in C:\users.
rem 4. Scan the users.txt file getting all the usernames that have logged into the pc before and assing them as %%A.
rem 5. Check to see if 3CX Windows phone is installed on the pc. If it is not it will stop.
rem 6. Copy the users welcome email 3cxconfig file form the network share to c:\temp.
rem 7. Run the 3cxconfig file. This will genereate the 3cxPhone.xml file with the users settings and place it under
rem the AppData folder for the account that is running the script.
rem 8. Take a 3 second pause for the 3cx windows client to fully launch and generate the 3cxPhone.xml file.
rem 9. Copy newly generated 3CXPhone.xml file from the user account that is running the batch file and place it in
rem the users AppData folder that the config file corresponds with.
rem 10. Kill the 3CXPhone process that is running in the background created by executing the 3cxconfig file.
rem 11. Delete the Welcome Email 3cxconfig file that was copied to c:\temp.
rem 12. Delete the Users.txt file created in C:\temp and delete 3CXPhone.html in script runner user's folder.
rem 13. Goto c:\temp.
rem 14. Scan the C:\users directory for all users,
rem 15. Check if they have a 3cxconfig file already setup for their user name.
rem 16. If they do, Copy the powershell script to modify the config file for that user.
rem 17. Copy the companyheader logo you want to use for that client.
rem 17. Run the powershell script
rem 18. The powershell script scans the users config file and replacees whatever settings you want with new ones.
rem
rem
rem Feel free to modify this all you want, I hoping it won't be useful for much longer considering 3CX is working hard towards
rem allowing management of the Softphone app from within the 3CX console.
rem
rem Below is the powershell script. Copy it and save it to a text file with the name of 3cxscript.ps1 (not ending in .txt)
rem Make sure to remove all the "rem" comments at the beginning of each line and the additonal two spaces.
rem (Copy below this line)
rem
rem Set-ExecutionPolicy RemoteSigned
rem $original_file = '3CXPhone.xml'
rem $destination_file = '3CXPhone.xml'
rem (Get-Content $original_file) | Foreach-Object {
rem $_ -replace '<IsCustomImageSet>False</IsCustomImageSet>', '<IsCustomImageSet>True</IsCustomImageSet>' `
rem -replace '<CustomImagePath></CustomImagePath>', '<CustomImagePath>C:\ProgramData\3CXPhone for Windows\PhoneApp\HeaderImage.jpeg</CustomImagePath>' `
rem -replace '<ApplicationTheme>3</ApplicationTheme>', '<ApplicationTheme>1</ApplicationTheme>' `
rem -replace '<ApplicationTheme>2</ApplicationTheme>', '<ApplicationTheme>1</ApplicationTheme>' `
rem -replace '<StealFocusOnIncomingCall>False</StealFocusOnIncomingCall>', '<StealFocusOnIncomingCall>True</StealFocusOnIncomingCall>' `
rem -replace '<AutomaticallyOpenChatWindow>False</AutomaticallyOpenChatWindow>', '<AutomaticallyOpenChatWindow>True</AutomaticallyOpenChatWindow>' `
rem } | Set-Content $destination_file
rem
rem (Copy above this line)
rem
rem If you want to install the 3cx client as well just add the below lines and remove the "rem" tags.
rem
rem cd c:\temp\
rem xcopy /f /i /y "(NWPATH)\3CXPhoneforWindows15.msi" "C:\temp\3CXPhoneforWindows15.msi*"
rem msiexec /i 3CXPhoneforWindows15.msi /quiet
rem
rem
rem Step 1
taskkill /FI "WINDOWTITLE eq 3CX*" /F
taskkill /im 3CXWin8Phone.exe /f
taskkill /im 3CXWIN~1.exe /f
rem Step 2
cd C:\users\
rem Step 3
dir /b > C:\temp\users.txt
rem Steps 4-11
for /F %%A in (C:\temp\users.txt) do if exist "C:\ProgramData\3CXPhone for Windows\PhoneApp\" xcopy /f /i /y "(NWPATH)\%%A.3cxconfig" "c:\temp\%%A.3cxconfig*" && cd C:\temp\ && del "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml.back" && del "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml" && ping localhost -n 10 >NUL && start "C:\temp\%%A.3cxconfig" && ping localhost -n 10 >NUL && xcopy /f /i /y "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml" "C:\Users\%%A\AppData\Roaming\3CXPhone for Windows\3CXPhone.xml" && taskkill /FI "WINDOWTITLE eq 3CX*" /F && taskkill /im 3CXWin8Phone.exe /f && taskkill /im 3CXWIN~1.exe /f && del "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml" && del "C:\temp\%%A.3cxconfig" && ping localhost -n 10 >NUL && del "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml.back" && del "C:\users\(deployuser)\appdata\roaming\3cxphone for windows\3CXPhone.xml"
rem Step 12
del "C:\temp\users.txt"
rem Step 13
cd C:\temp
rem Step 14-18
for /d %%B in (C:\Users\*) do if exist "%%B\AppData\Roaming\3CXPhone for Windows\" cd %%B\AppData\Roaming\3CXPhone for Windows && copy /y \\(NWPATH)\3cxscript.ps1 && copy /y \\(NWPATH)\HeaderImage.jpeg "C:\ProgramData\3CXPhone for Windows\PhoneApp\HeaderImage.jpeg" && copy /y \\(NWPATH)\Default.wma "C:\ProgramData\3CXPhone for Windows\PhoneApp\Notifications\Default.wma" && powershell -ExecutionPolicy ByPass -File .\3cxscript.ps1