I recently had cause to install an old piece of software on 20 computers in a lab, and was looking for a way to automate this installation to reduce the tedium and opportunity for mistakes inherent in such a repetitive task.
Optimally, of course, the software would have come with a .MSI installer, and I would have just used wmic or Powershell to copy the the MSI and run it with the /quiet switch for a silent install. However, this application's installer was created with Clickteam Install Creator, so takes the form of a standard .EXE - and, what's more, it was created with the non-Pro version, so there is no silent installation switch. I tried all the standard tricks, including opening the installer in 7Zip to see if it simply hid an MSI (like some InstallShield installers), but it seemed like nothing was going to work. So, I got creative.
In the past, I have used AutoIt to script mouse movements and clicks. This would work in my use case, but I did not want to install the program just to install one other program, so it was out. Then, I realized that everything in the installer could be maneuvered with a combination of presses of the Tab, Enter, and arrow keys, and that if I could write a batch or Powershell script to send those keys to the installer application, I could do it with no additional software required. It wouldn't be a silent install, and would require logging in to the computer to start the script, but it would be more-or-less automated.
It turns out that, as of this writing, Powershell does not have a native cmdlet or other provision to send keys to another application. Luckily, there are two different methods to use Powershell for this: the Windows Script Host COM object, or a .NET assembly. In our case, because our other techs are more familiar with WSH scripting than with .NET, I chose to use that option.
The Windows Script Host COM component can provide a shell object that allows you to send keystrokes to a window, which behaves just as if a user had physically pressed the keys. To create the shell object and send a keystroke, you can use the following code:
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate("name of window to send keystrokes to")
$wshell.SendKeys("keystrokes to send")
For the most part, I only needed to send Tab, Enter, and arrow key strokes, whose codes are, respectively, {TAB}, {ENTER}, {UP}, {DOWN}, {LEFT}, and {RIGHT}. Many other keycodes are available for other use cases. I found that several of the SendKeys commands in order were in fact going too fast for the installer to keep up, so I inserted some Powershell pauses between them:
Start-Sleep -s 1
to make sure that the installation proceeded correctly, as well as some longer pauses to allow the actual installations to take place before the final screen and "Finish" button keypresses.
Now, the installation was automated, but I would still need to log in to each computer, navigate to the script, right-click to Run as Administrator, and click "Allow." I wanted to automate this as much as possible, so I didn't stop there. I created a batch file that would run my installer script as an administrator user automatically:
powershell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process Powershell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\install.ps1""' -Verb RunAs}"
and placed it in the Start Up folder so that it would run automatically on login:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
I then added a line to the installer script to delete this startup script when the installation was complete, so that it would not re-install the program on each login.
With this setup in place, the once-laborious install was reduced to:
1. Copy the installer application, install script, and startup script to the appropriate locations on the remote computer, using the \\computername\C$ share (also done via Powershell with a for loop).
2. Log in to each machine as an administrator user.
3. Click "Allow" on the UAC prompt.
4. Wait until the install finishes.
Before automation, installing this software on all 20 lab computers might have taken around 40 minutes; after automation, the whole-lab install took about 10 minutes, and considerably reduced the chances that an incorrect option may have been selected in the installer on some machines.
Subscribe to:
Post Comments (Atom)
Tableau, TabPy, and the Case of No Input Rows
I haven't scientifically confirmed this or anything, but it sure seems like if you pass an empty dataframe to a TabPy script, then no m...
-
Configuration Profiles are Apple's somewhat newer, MDM-esque management solution for Macs, similar to how iPads and iPhones are managed....
-
Among other applications, we deploy Apple's GarageBand using Munki. GarageBand can be installed without too much trouble, but on first ...
-
I recently had cause to install an old piece of software on 20 computers in a lab, and was looking for a way to automate this installation t...
No comments:
Post a Comment