Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

How to set 3CX Windows Client status on login silently - script/bat files included

Discussion in 'Windows' started by dan_tx, Nov 20, 2017.

Thread Status:
Not open for further replies.
  1. dan_tx

    dan_tx New Member

    Nov 3, 2016
    Likes Received:
    So we plan to use the 3cx windows client feature to auto away after about 15 minutes so users can tell if someone is at their desk or not before calling them. Also in the mornings you can tell if someone has arrived at their desk as soon as their status changes. We still want the phone to ring, so we changed the name of the default "Available2" status to "Away from Computer". Then set the auto-away to change to that status. That way the phone rings, but the status still changes.

    Now users have a good indication if the person is at their desk. So this works great.

    The problem is if the computer restarts or the 3cx client is closed while in the "Away from Computer" status, when launching it backup up it does not come back to Available even with mouse movement.

    While it would have been easier to use the calltrigger to dial command set status to available, we do not want users phones dialing without them doing the dialing and we wanted the status change to be invisible to the user. The solution appeared to be use calltriggercmd.exe to set the active profile. It would have been nice if you could somehow reference the status name, but it appears you have to use the VALUE (1-999?)and the value is different for each user. *You must have Pro edition or higher to use calltriggercmd.exe *

    While I'm certain there is an easier why to do this with a script, I was unable to find one offered by anyone on the forums so made one and am posting it below. You can adjust it to the change the status to anything on login, right now it is set to change the status to "Available".

    You will need to adjust the share path to a network drive you keep the files in. Basically the login script runs a bat file invisibly that runs several commands including another script file. A step breakdown is included.

    ' Bat and Script to change 3cx status to available via calltriggercmd.exe at login. 
    ' Anywhere it says *NETWORKPATH* you need to adjust to whever you put the file on your network
    ' Step0 Timeout to allow 3cx time to launch windows client after logon
    ' Step1 makes temp dir for files
    ' Step2 deletes files that will be used on this login if they exist and checks if 3cx is installed
    ' Step3 copies the 3cxscan.vbs script that scans the 3cxstatus.txt file for the code for Available status
    ' Step4 Gets the available profiles for the user and outputs them to 3cxstatus.txt.
    ' Then runs the 3cxscan.vbs script on the file and outputs the Available code to the 3cxoutput.txt file
    ' Step5 sets the Available code in the 3cxoutput.txt as a variable and runs calltrigger to set profile to that status
    ' Step6 Deletes txt files and script from temp folder
    ' The 3cxscan.vbs code is below. Make the script using the code below inside the '''' and call it 3cxscan.vbs. 
    ' Place in the share path you want it then point the script to it
    ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '  Option Explicit
    '  Dim goFS     : Set goFS = CreateObject( "Scripting.FileSystemObject" )
    '  Dim reCut : Set reCut = New RegExp
    '  reCut.Global = True
    '  reCut.Pattern = "(\d*)    Available"
    '  Dim oMTS : Set oMTS = reCut.Execute(goFS.OpenTextFile("c:\temp\3cxstatus.txt").ReadAll)
    '  Dim oMT
    '  For Each oMT IN oMTS
    '      WScript.Echo oMT.SubMatches(0)
    '  Next
    ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' The logon script is below. Add it to the GPO. Run this instead of the bat so
    '  the command prompt window will not show up for the users.
    ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Set objShell = WScript.CreateObject("WScript.Shell")
    ' objShell.Run "cmd /c *NETWORKPATH*\3cxbat.bat", 0, True
    ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    timeout 5
    if exist C:\temp goto Step2 else mkdir C:\temp
    if exist C:\temp\3cxstatus.txt del C:\temp\3cxstatus.txt
    if exist C:\temp\3cxoutput.txt del c:\temp\3cxoutput.txt
    if exist C:\temp\3cxscan.vbs del c:\temp\3cxscan.vbs
    if exist "C:\ProgramData\3CXPhone for Windows\PhoneApp\CallTriggerCmd.exe" goto :Step3 else goto :End
    copy /y *NETWORKPATH*\3cxscan.vbs C:\temp\3cxscan.vbs
    "C:\ProgramData\3CXPhone for Windows\PhoneApp\CallTriggerCmd.exe" -p >> C:\temp\3cxstatus.txt
    cscript.exe //NoLogo C:\temp\3cxscan.vbs >C:\temp\3cxoutput.txt
    set /p StatusID=<C:\temp\3cxoutput.txt
    "C:\ProgramData\3CXPhone for Windows\PhoneApp\CallTriggerCmd.exe" --set-active-profile=%StatusID%
    if exist C:\temp\3cxstatus.txt del C:\temp\3cxstatus.txt
    if exist C:\temp\3cxoutput.txt del c:\temp\3cxoutput.txt
    if exist C:\temp\3cxscan.vbs del c:\temp\3cxscan.vbs
    #1 dan_tx, Nov 20, 2017
    Last edited: Nov 20, 2017
    Lewis Burgess likes this.
Thread Status:
Not open for further replies.