Virtual Network Computing (VNC) allows you to remotely control computers. However, before you can work with VNC, you first have to install it on remote computers. You can do this with PowerShell.

VNC logoVNC is one of the most popular remote desktop control products out there. It's free and comes in many different flavors that administrators can pick from. Regardless of which software you use that implements VNC, they all require a software installation on the server (the computer you're connecting to) and the client (the computer initiating the connection).

If you're a desktop administrator, I'm sure there's been a time whenever you needed to VNC to a user's desktop, only to find that VNC was not installed yet. At that point, you might have talked the user through installing VNC on the server from a file share somewhere on the network. However, this takes time and resources, so it's much better to automate this process and directly send the installation files remotely, with no user interaction at all. In this article, I'll show you how to build a PowerShell script that allows you to remotely install UltraVNC on as many computers as you need.

Before we get too far, however, we first need to figure out the switches required to make the install silent. Depending on the software, this might be either an easy experience or an incredibly frustrating one. While browsing in Itninja's software library, I discovered that I needed to first perform a single install and save all the answers I provided to in an INF file with the /saveinf switch.

Setup.exe /saveinf="C:\silentinstall.inf"

This will save a file called silentinstall.inf to the root of my C drive.

Next, I need to figure out how to use this answer file when installing UltraVNC on another computer. This is possible using the /loadinf switch and passing the file name in the same manner.

Setup.exe /loadinf="C:\silentinstall.inf"

This works, but doesn't make the install completely silent like I need it to be. To do that, I need to add another switch to this: /verysilent.

Setup.exe /verysilent /loadinf="C:\silentinstall.inf"

When executed, this syntax will silently install UltraVNC with all the same answers I initially provided, which are manually saved in the INF file. Great! We now have the ability to silently install this software on a machine. However, we have no way to do this to remote computers. The way it is now, we’d have to manually copy the setup.exe and the INF file to remote computers. This is very inefficient. Let's automate all of this with a PowerShell function.

Since we already have everything necessary to perform the install locally, now we need to first figure out where we're going to store the setup.exe file and the INF file. We’ll learn how to make these files accessible to every computer, deliver those bits to a remote computer, and execute the install remotely.

Because we'll probably need to reference the installer bits over and over again, it's a good idea to place them on a file share somewhere on the network. I'll put them on a share called ToolShare on my MEMBERSRV1 server.

$InstallerFolder = '\\MEMBERSRV1\ToolShare\VNC'

Next, I need to copy the setup.exe and the INF file to remote computers on demand. To do this, I Copy-Item to do a simple file copy of the entire VNC folder.

$ClientName = 'MYCLIENT'
Copy-Item –Path $InstallerFolder –Destination \\$ClientName\c$ -Recurse

Next, I need to invoke the install remotely. PowerShell remoting is an excellent way to make this happen. I'll use the Invoke-Command to remotely execute the silent install from my computer.

To do this, I first need to wrap the command I need to run in a scriptblock.

$scriptBlock = {
   Start-Process "C:\VNC\setup.exe" -Args "/verysilent /loadinf=`"C:\VNC\silentinstall.inf`"" -Wait -NoNewWindow
}

You can see I'm using the Start-Process cmdlet to kick off the installer on the remote computer and am passing the silent arguments.

Next, I need to execute this script on the remote computer with the Invoke-Command cmdlet.

Invoke-Command -ComputerName $ClientName -ScriptBlock $scriptBlock

This sends instructions to $ClientName to run the code inside of the scriptblock. After this is complete, we're done! UltraVNC is installed. However, we've now left that C:\VNC folder on the remote computer. Let's clean that up.

Subscribe to 4sysops newsletter!

Remove-Item \\$ClientName\c$\VNC -Recurse

We've now installed UltraVNC and cleaned up any remnants we've left behind. If you like this approach, feel free to download the Deploy-VNC script from my Github repo. It encapsulates all of this code into a PowerShell function and includes better functionality.

avatar
8 Comments
  1. Johan 6 years ago

    hello, have you some trick to install silently VNC driver too?

     

  2. johnde 6 years ago

    Hi
    …. and start the vnc-service with a password in the background.

    john

  3. Author
    Adam Bertram 6 years ago

    I sure don’t although I’d say if you could figure out how to install it silently, you could use the same approach as I did here.

    • john 6 years ago

      Unfortunately i was not able to figure out, how to do this. So the remote Computers are not accessible anymore after Installation  🙁
      Any Ideas are welcome. Thx.
      John

      • Author
        Adam Bertram 6 years ago

        Did you verify that the install syntax you used worked manually without doing it remotely?

  4. Dusan 6 years ago

    Hi Adam,

    I am wondering if the same approach can be used for installing remotely other .exe files?

    I have got two KB.exe for outllook to support MAPI/HTTP and cannot figure out how to install it on targeted client computers. I am trying to use start-process, then can see the process running, but nothing happening. Using switches /s /q don’t help and if I run it as a background job, it fails straight away. Any suggestions?

  5. Danny 3 years ago

    How about setting up the password for VNC? Could that be bundled in the script somehow?

Leave a reply

Your email address will not be published.

*

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account