# Disable the UltraVNC System Tray Icon

## PowerShell Script

The UltraVNC System Tray Icon can be disabled by using a custom PowerShell script.

The following script is the Disable UltraVNC Tray Icon sample PowerShell script. Copy it and save it as a **.ps1** file. For further information on hosting this script see [Quick Guide to Self-Hosting Custom Scripts](https://docs.faronics.com/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/quick-guide-to-self-hosting-custom-scripts). &#x20;

### Disable UltraVNC Tray Icon Script

This script disables the UltraVNC Tray Icon on the computer it is run on.&#x20;

{% hint style="info" %}
Note: Once this script is run, you will need to **log off the current user session** for the changes to come into effect.
{% endhint %}

```javascript
# How to use this script
# HideUVNCTrayIcon.ps1 <Download_URL>  

param(
    [string]$URL,
    [string]$filename
)

$ScriptRoot = $PSScriptRoot
if ([string]::IsNullOrEmpty($ScriptRoot)) {
    $ScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}

$LogDir = "$ScriptRoot"
$LogFile = "$LogDir\HideUVNCTrayIcon.Log"
$ERROR_SUCCESS = 0
$ERROR_FAILED = 1
$ERROR_EXCEPTION_OCCURED = -1
$DownloadPath = "$ScriptRoot\"


$ERROR_PS_VER_LOWER = 20008
$versionMinimum = [Version]'3.0.99999.999'
Function ExitIfPSVersionLower {

    Log -logstring ("Info: PowerShell version is: " + $PSVersionTable.PSVersion)

    if ($versionMinimum -gt $PSVersionTable.PSVersion) {
        Log -logstring "Error: This script requires minimun PowerShell version: $versionMinimum"
        Exit $ERROR_PS_VER_LOWER
    }
}

Function CreateLogDir {
    If (!(Test-Path $LogDir)) {
        mkdir $LogDir | out-null
    }
}
Function Log {
    param(
        [Parameter(Mandatory = $true)][string]$logstring
    )

    $Logtime = Get-Date -Format "dd/MM/yyyy HH:mm:ss:fff"
    $logToWrite = "{$Logtime[PID:$PID]} : $logstring"
    Write-Host($logToWrite)
    Add-content $LogFile -value ($logToWrite)            
}

trap {
    Log -logstring "Exception occured in HideUVNCTrayIcon Script"
    $message = $Error[0].Exception.Message
    if ($message) {
        Log -logstring "EXCEPTION: $message"
    }

    Log -logstring "Exit from HideUVNCTrayIcon Script With Exitcode=$ERROR_EXCEPTION_OCCURED `r`n`r`n"
    exit $ERROR_EXCEPTION_OCCURED
}

function DownloadFile {

    if ([string]::IsNullOrEmpty($URL)) {
        Log -logstring "Error: file URL is not specified"
        $DownloadPath = ""
        return $DownloadPath
    }

    Log -logstring  "Download URL: $URL"
    
    #[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11

    #Log -logstring "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11"

    if ([string]::IsNullOrEmpty($filename)) {
        $filename = "HideUVNCTrayIcon.exe" 
    }

    $DownloadPath = ($DownloadPath + $filename)
    Log -logstring  "Download Path: $DownloadPath"
    Invoke-WebRequest -Uri $URL -OutFile $DownloadPath -UseBasicParsing

    if (!(Test-Path $DownloadPath)) {
        Log -logstring ("Error: Failed to download file. Path: " + $DownloadPath)
        $DownloadPath = ""
    } 

    return $DownloadPath
}

try {
    Push-Location $ScriptRoot
    # Create Log directory
    CreateLogDir
    Log -logstring "Inside HideUVNCTrayIcon Script"
    ExitIfPSVersionLower

    $DownloadPath = DownloadFile
    if (![string]::IsNullOrEmpty($DownloadPath)) {
        Log -logstring "Download Success: $DownloadPath"
        $ReturnValue = $ERROR_SUCCESS

        # Hide Tray Icon
        & $DownloadPath 1

        #Show Tray Icon
        # & $DownloadPath 0
    }
    else {
        Log -logstring "Download Failed"
        $ReturnValue = $ERROR_FAILED
    }
    Log -logstring "Exit from HideUVNCTrayIcon Script with Exitcode = $ReturnValue `r`n`r`n"
    Exit $ReturnValue
}
finally {
    Pop-Location
}
```

## Custom Script Settings

The table below outlines all the fields that need to be set when creating this custom script.&#x20;

{% hint style="info" %}
For a detailed guide, refer to [Create a Disable UltraVNC Tray Icon Script](#create-a-disable-ultravnc-system-tray-icon-custom-script).
{% endhint %}

| Field        | Value                                                    |
| ------------ | -------------------------------------------------------- |
| Name         | **Disable UltraVNC Tray Icon**                           |
| URL          | <http://faronics.org/proservices/HideUVNCTrayIcon.ps1>   |
| Type         | **PowerShell**                                           |
| Command-Line | "<http://faronics.org/proservices/HideUVNCTrayIcon.exe>" |
| Run As       | **System Account** or **Specified User Account**         |

## Create a Disable UltraVNC System Tray Icon Custom Script

![Create a Custom Script](https://3007061244-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRkQfx_2cLnNNBX1muO%2F-MVTElzvvVzBy4ilZBk4%2F-MVTMQo7yXAzeNjC65UE%2Fimage.png?alt=media\&token=7a0a3ba4-1ce4-4768-af51-34d6956c7572)

1\. Select the **Control Grid** tab on the top menu bar.

2\. Navigate to the **Applications** tab.

3\. Click **CUSTOM** **SCRIPT**.

4\. Select **Create** **Custom** **Script**.

5\. Enter a **Name** for the script, **Disable UltraVNC Tray Icon** in this example. Use any name you'd like to use.

![Creating a Custom Script for Disable UltraVNC Tray Icon](https://3007061244-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MRkQfx_2cLnNNBX1muO%2F-M_WhtS_NNrcnbxDk-vc%2F-M_X65NL2GTSOycvMveG%2Fimage.png?alt=media\&token=f29e60a3-bd32-44f4-a19a-97e9bc0b19b2)

6\. Enter the **URL** that points to the location where the script is being hosted,  <http://faronics.org/proservices/HideUVNCTrayIcon.ps1> in this example. You might need to download this file and host it on a link that is whitelisted in your firewall.

{% hint style="info" %}
Best Practice is to download the sample script and self-host it. You can do this for free with GitHub. See the [Quick Guide to Self-Hosting Custom Scripts](https://docs.faronics.com/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/quick-guide-to-self-hosting-custom-scripts) for more information.
{% endhint %}

7\. Select the script type: **Powershell**.

8\. **Command Line**: Enter the path to the **exe file** inside double-quotes "<http://faronics.org/proservices/HideUVNCTrayIcon.exe>" .

{% hint style="info" %}
The double-quotes **" "** are **required** around the command line parameter.&#x20;
{% endhint %}

9\. Select the account to **Run As**; either **System Accoun**t or **Specified User Account**.

10\. Click **SAVE TO GRID**.

{% hint style="info" %}
Once saved, the script can be pushed to an individual computer or groups of computers. It can also be scheduled using a Policy.

For a guide on how to run your Custom Script, see [Pushing the Script](https://docs.faronics.com/faronicsdeploy/custom-scripts-powershell-vb-batch/..#pushing-the-script).
{% endhint %}

{% hint style="success" %}
The script will now appear in the list of Custom Scripts. It will also be available to select from the Applications Control Grid View.&#x20;

Search for the script in the grid using the search option. If your applications are grouped, you will see a column named **Custom** **Scripts**. Selecting the **Custom Script header** will display all the scripts that have been added to the grid.&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.faronics.com/faronicsdeploy/custom-scripts-powershell-vb-batch/custom-scripts-library/disable-the-ultravnc-system-tray-icon.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
