Automating the World

We have migrated servers, if you encounter any issues, please let us know on Slack, or post it.


We have also disabled registration as we migrate to the new forum systems. The slack (slack.labtechgeek.com) will always be accepting new users.
 
User avatar
DarrenWhite99
Geek
Topic Author
Posts: 513
Joined: Wed Jun 04, 2014 11:17 pm
Current LT Agent Count: 1500+
Location: Redding, California, US

CW Control / Screen Connect Command Execution Tips

Thu Jun 08, 2017 1:01 am

ConnectWise Control (Screen Connect) allows you to run a command and get a response from their web interface. It is quick, very convenient when CWA isn't up to the task for whatever reason, but it also has some quirks. Large results will be truncated. Long running commands will be killed. Your command can be trapped in a 32bit cage on a 64bit system. Here are some tips to make it work better for you:

  1. You can enter multi-line commands by pressing shift-enter.
  2. You can include special variables above your commands to control how the command is processed.
    1. #!ps <- Will execute all commands below using Powershell.exe instead of CMD.exe. (Will use 32-bit PowerShell, even on a 64-bit OS)
    2. #!cmd <- Apparently that is also supported.
    3. #maxlength=X <- Specify how many bytes the command can return.
    4. #timeout=X <- Specify command timeout in milliseconds. -1 is for a very long time.
  3. You can always execute as 64-bit on 64-bit systems if you prefix your command with: "%windir%\sysnative\cmd.exe /c "
  4. Alternately, for 64-bit powershell you can call it as "%windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe"

Using sysnative only works when you are in a 32 bit environment on a 64 bit OS. The folder does not exist when you are in a native 64 bit environment.

Other Tips? Share them!
Last edited by DarrenWhite99 on Thu Jun 08, 2017 4:39 am, edited 1 time in total.
 
User avatar
DarrenWhite99
Geek
Topic Author
Posts: 513
Joined: Wed Jun 04, 2014 11:17 pm
Current LT Agent Count: 1500+
Location: Redding, California, US

Re: CW Control / Screen Connect Command Execution Tips

Thu Jun 08, 2017 4:31 am

So, a little more detail on the maxlength and timeout values. The SC 5.2 releaselog documented the following details about those parameters:
allowed specifying shebang such as #!ps on first line to pick script interpreter for commands (including the normal /bin/sh or /bin/bash able to be specified on linux/osx)
allowed specifying #maxlength=234234234234 for command to specify script max return size
allowed specifying #timeout=90234234 for command to specify script timeout

From http://forum.screenconnect.com/yaf_postst5146_ScreenConnect-5-2-Release-Log.aspx
 
Derek-ETS
Posts: 11
Joined: Fri Nov 13, 2015 9:27 am
Current LT Agent Count: 3000+

Re: CW Control / Screen Connect Command Execution Tips

Thu Jun 08, 2017 3:09 pm

You will want to put your variables on separate lines, otherwise I've noticed they tend to not execute as expected.
Format example:
#!ps
#maxlength={value}
#timeout={value}
{Command}
 
User avatar
DarrenWhite99
Geek
Topic Author
Posts: 513
Joined: Wed Jun 04, 2014 11:17 pm
Current LT Agent Count: 1500+
Location: Redding, California, US

Re: CW Control / Screen Connect Command Execution Tips

Thu Sep 07, 2017 6:21 am

To reinstall CWA Using ConnectWise Control, use the following remote command to get a 64 bit process if CWControl is a 32bit version.
#maxlength=5000
#timeout=600000
"%windir%\sysnative\WindowsPowerShell\v1.0\powershell.exe" "(new-object Net.WebClient).DownloadString('http://bit.ly/LTPoSh') | iex; Reinstall-LTService"

If it immediately returns an error, use the normal command:
#maxlength=5000
#timeout=600000
"%windir%\system32\WindowsPowerShell\v1.0\powershell.exe" "(new-object Net.WebClient).DownloadString('http://bit.ly/LTPoSh') | iex; Reinstall-LTService"

I am posting this as much a reminder for myself as to be helpful for someone else. :)