Jump to content
DarrenWhite99

Easy Agent Installation Launcher to select the Location for Deployment

Recommended Posts

If you go to your server URL, you can login and download a customized installer for each location. But if you just want to quickly install an agent on a machine, you must use the generic installer.  Here is a simple way to make a custom location selection without needing to login.

Create a file named myagent.hta, or agentinstall.hta, etc. on your server. It could be in the root,. or under /LabTech/Transfer/.

Save the following contents into the file, replacing "your.server.here" with your server URL.

<html>
    <head>
        <title>Automate Agent Deployment</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <hta:application applicationname="Automate Agent Deployment" version="1.1"    />
        
        <script language="vbscript">
        Sub ResizeWindow()
            window.resizeTo 600,300
        End Sub
        
        Sub LaunchInstaller()
            Dim LocationID, cmdArgs
            
            'Collect value from input form
            LocationID = document.getElementByID("Location_id").Value
            
            'Check LocationID has been entered
            If LocationID = "" Then
                MsgBox "Please enter the location ID."
                Exit Sub
            End If
            
            'Set parameters to powershell command
            cmdArgs = "-command ""(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | IEX; Install-LTService -Server 'https://your.server.here' -LocationID '" & LocationID & "'"""

            Set oShell = CreateObject("Shell.Application")
            oShell.ShellExecute "powershell.exe", cmdArgs, "", "runas", 1

        End Sub
        </script>
    </head>
    
    <body onload="ResizeWindow()">
        <h1>Automate Agent Deployment</h1>
        <div>Location ID:</div>
        <input type="text" id="Location_id" value="" />
        <br>
        <input type="button" id="install_btn" value="Start Installation" onclick="LaunchInstaller()" />
    </body>
</html>

Now, just go to "http://your.server.here/agent.hta". (Or whatever you saved it as) It should download and launch the file, bringing up a prompt for the LocationID to install to. Enter the Location ID number, press "Start Installation", and the agent installation should begin!

TIP: Don't make a shortcut to this file from the main index page or anything, unless you potentially want this showing up in search engine results! :) 

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites

Hey Darrin, 

I'm getting some powershell errors after I select the location ID.I tried to snap a better screen shot but it was quick. 

 image.png.f243d38f27cd18cc1c7ace60c199f408.png

Share this post


Link to post
Share on other sites

From that error, I can see that it is trying to run from a 32bit instance of powershell (possibly because the browser/HTA application is 32bit) and that does not work... Good news! I will be pushing a change to the LTPosh module soon that attempts to automatically work around that issue (if possible)!  You can test the changes from my branch now by downloading from https://raw.githubusercontent.com/DarrenWhite99/LabTech-Powershell-Module/X64onX86/LabTech.psm1

Once the changes are accepted, I will be deleting that branch (I only created it to address this specific issue) so make sure that you don't rely on that link too much.  Actually, you could modify the HTA to handle the 32bit on 64bit OS issue: 

Replace:
cmdArgs = "-command ""(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | IEX; Install-LTService -Server 'https://your.server.here' -LocationID '" & LocationID & "'"""
With:
cmdArgs = "-command ""if ($env:PROCESSOR_ARCHITEW6432 -match '64' -and [IntPtr]::Size -ne 8) { &""$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe"" -NonInteractive -NoProfile $myInvocation.MyCommand; exit;}; (new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | IEX; Install-LTService -Server 'https://your.server.here' -LocationID '" & LocationID & "'"""

 

Share this post


Link to post
Share on other sites

How's your experience been with this on Windows 10? I have had my team test this on some new machines, said Windows Defender detects it as a virus out of the box, once allowing it through that, it throws errors. They said the errors looked like to be with the .net part, but they couldnt see for sure. Tried running again, reboots, said no errors but it didnt work.

I havent looked personally at it yet. I suspected it was an admin / UAC thing, but they said they don't have options to run .hta as admin and the 2 seconds of googling I did on it seemed to suggest similar.

 

Share this post


Link to post
Share on other sites

I built/tested it on Windows 10. I have UAC enabled and it worked fine. It MUST be saved as a local file and ran, it will not launch from a URL. It will try and launch the elevated command, so if UAC is enabled you will get a prompt to approve the command.

The HTA will not be elevated, the elevation will occur if needed as the powershell command is called.

Share this post


Link to post
Share on other sites

I'm stumped. When I download the .hta file to a system, I'm getting error messages saying the ResizeWindow function isn't defined. And sure enough, when I view the HTML source of the HTA file downloaded, it's completely missing the <script> blocks.  Any ideas?

The file on my CWA server is this:

<html>
    <head>
        <title>Enable Automate Agent Deployment</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <hta:application applicationname="Automate Agent Deployment" version="1.1"    />
        
        <script language="vbscript">
        Sub ResizeWindow()
            window.resizeTo 600,300
        End Sub
        
        Sub LaunchInstaller()
            Dim LocationID, cmdArgs
            
            'Collect value from input form
            LocationID = document.getElementByID("Location_id").Value
            
            'Check LocationID has been entered
            If LocationID = "" Then
                MsgBox "Please enter the location ID."
                Exit Sub
            End If
            
            'Set parameters to powershell command
            cmdArgs = "-command ""(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | IEX; Install-LTService -Server 'https://automateurlhere.com' -LocationID '" & LocationID & "'"""

            Set oShell = CreateObject("Shell.Application")
            oShell.ShellExecute "powershell.exe", cmdArgs, "", "runas", 1

        End Sub
        </script>
    </head>
    
    <body onload="ResizeWindow()">
        <h1>Enable Automate Agent Deployment</h1>
        <div>Location ID:</div>
        <input type="text" id="Location_id" value="" />
        <br>
        <input type="button" id="install_btn" value="Start Installation" onclick="LaunchInstaller()" />
    </body>
</html>


But when I download the HTA file through a browser, it comes out like this (Notice the <script> block is completely missing):

<html>
    <head>
        <title>Enable Automate Agent Deployment</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <hta:application applicationname="Automate Agent Deployment" version="1.1"    />
        
        
    </head>
    
    <body onload="ResizeWindow()">
        <h1>Enable Automate Agent Deployment</h1>
        <div>Location ID:</div>
        <input type="text" id="Location_id" value="" />
        <br>
        <input type="button" id="install_btn" value="Start Installation" onclick="LaunchInstaller()" />
    </body>
</html>

 

Edited by tlphipps

Share this post


Link to post
Share on other sites

It sounds like it is trying to execute the file on the server side somehow. It should just be downloaded without any changes so that it can be executed locally. I have honestly only tested local copies, so I don't know what issues you might run into putting it on the server and downloading in a browser.  It probably should be kept in the /LabTech/Transfer/ path, not under /WCC2 or /automate or anything like that.

Share this post


Link to post
Share on other sites

OMG. So I figured out what's happening. Bitdefender is stripping out the <script> tags from the file. Between the time I've saved the file locally on my laptop and then copied it up to the server, Bitdefender has already gone in and modified the file to completely remove the <script> section because of the VBscript declaration in there. I had no idea it could/would modify the CONTENTS of the file rather than just quarantining the entire thing. So that's a new one for me.

Oh, and even Windows Defender will flag and delete the file if downloaded from a webserver. So yeah, fun.

I guess it's time to learn how to build a powershell GUI.

Edited by tlphipps

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...