Batch file / powershell: downloading and silent installing script - batch-file

I am trying to write a script that will, ideally, download the .exe/.msi files for different programs, and run them silently. These installations do usually require input, like clicking next, or check a radio button. If I know what installation settings I want to run, how can I get these installations to run them in the way I want, but silently? Will the coding be simplier to do using batch programming or using Powershell? (I am a complete beginner to both, so no preference. Suggestions would be much appreciated). The script would ideally then be packaged up into it's own .exe file to run on any windows computer.

Downloading the Installers
This is the easy part. In PowerShell 3 or newer, you can download via Invoke-WebRequest:
Invoke-WebRequest 'http://example.com/installer.exe' -OutFile 'installer.exe'
In earlier versions, you can create a WebClient object and use its DownloadFile method:
$Client = New-Object System.Net.WebClient
$Client.DownloadFile('http://example.com/installer.exe', 'installer.exe')
If you had a text file listing all the installers you needed to download, one URL per line, you could download them all like so:
Get-Content 'installers.txt' | % { Invoke-WebRequest $_ -OutFile ($_ -replace '^.*?([^/]+$)', '$1') }
Running the Installers
This is the hard(er) part. Automating UIs is messy in general, and PowerShell doesn't go out of its way to support it. It can be done with the .NET Framework, but PowerShell is really better suited for manipulating data directly.
If you have to do UI automation, though, I'd recommend an alternative like AutoIt. AutoIt is a kind of mashup of VBScript, PowerShell, and a few other languages that makes it easy to do things like click buttons and enter text into text boxes automatically. It's commonly used to automate GUI installations.
Alternatively, consider repackaging the EXE installers as MSIs before deployment. MSIs are made for silent installs. Their property values can be self-contained (or stored in MST files) so that a user doesn't have to type them in at runtime, so there's no need to automate their UIs. Smart Package Community Edition (formerly WinInstall LE) is freeware that can scan the files and registry entries created by an installer and package them into an MSI file for you.
Hope this helps!

Another option is to use Chocolatey, but that depends on whether the required applications are already packaged (you can package your own as well, provided there are no licensing or redistribution limitations).

Related

silent install IBM data server client using response file, Anyone tried to install in D drive?

I am trying to install DB2 ibm data server client(version 11.1), silent install in my windows server. i am using response file for the installation. I gave the path in response file to install in D drive, but still it is installing in C drive only. the command i was using is: msiexec /i "MSI path" /q /l*v "log file path" RSP_FILE_PATH="response file path".
Check the following:
Installing Db2 products and features using a response
Some notes on MSI customization in general below.
And a link to the most commonly used library of packaging tips contributed by packagers:
https://www.itninja.com/software-library/company/ibm
Different Designs: The exact mechanism used to redirect a folder like that depends on the design of the application and the setup from the vendor, they often do something very non-standard so reverse engineering their solution fully or slightly is usually neccessary.
Itninja.com: Maybe have a look if you can find the software here in the itninja.com "software tips" section: https://www.itninja.com/software-library/company/ibm - this is a collection of comments people have made who have packaged and deployed the software in question - either unsuccessfully or successfully. I can't really tell what the exact product name is, please check.
Download: If you have a download link that is publicly accessible I can have a quick look at the MSI to determine how it is set up. Please be aware that it is much better to install an MSI directly via normal configuration mechanisms (setting public properties and / or creating a transform - sample here) than to run a setup.exe with response file (which sometimes is the only possibility depending on the overall deployment design).
How to make better use of MSI files
A couple of quick overviews:
How to parameterize msi file from electron builder
MSI Repackaging - free tool
And some further links for reference:
Change the value of a MSI property loaded from a DLL using a MSI transform
How to run an installation in /silent mode with adjusted settings

Sending zip files and keeping file paths consistent

I have created a GUI and Database for my company. I am trying to alpha test the program. I made the program so that everyone would place it on their C drive so that the file paths would stay consistent. When I email the zip folder to everyone it adds an extra folder that is causing errors to the file path (I believe the error occurs during extraction?). Does anyone know a good way to prevent this from happening? Thanks!
Although "xcopy deployment" is a valid method to deploy programs, it can come with complications, as you have discovered. Instead, you can create an actual installer program which is much more versatile.
For a lead-in on making an installer you can read Create MSI installer in Visual Studio 2017.
Make sure that the program uses locations as given in the Environment.SpecialFolder Enumeration so that it is automatically adapted for any (properly-configured) Windows installation.
Other installers are available, e.g. Inno Setup, which may offer simpler or more detailed configuration of some options like replacing or keeping older files, or installing prerequisites like a required framework version.

Automate Build script from Batch to MSBUILD/NANT

I am trying to automate a build process for a C# (vs2008) solution.
The build script is written in a Batch script which I want to change. We use Clearcase as the CM system. I have searched some tools such as MSBUILD, NANT.
Any suggestions which is a better solution like a sample script in MSBUILD and NANT?
I have not seen any sites where MSBUILD and NANT is documented well or any good tutorial about each task description.
Where I can learn MSBUILD or NANT either of them and write script from scratch?
There is a third way which I prefer. You can also use devenv.com. It's faster than NANT, doesn't require NANT bins and works on any machine with VS installed. You also avoid possible errors with MSBUILD (http://support.microsoft.com/kb/964125).
Just use %path_to_devenv.com%\devenv.com "%path_to_sln" /<buildoption> BuildConfig
In my case it's
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com "C:\Projects\XYZ\xyz.sln" /rebuild Debug
This way it's guaranteed that your project will be build exactly the same way as it's being built in Visual Studio.
EDIT:
Now that we know how how much there is to do, I'll try to give an outline how you can setup the whole system for automated build controll.
Set up your repository (I hope this is already done - tell me if not)
Install and set up Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins) including users, ClearCase-Credentials, plug-ins for ClearCase, MSBuild, etc. (all of them can be found in the Jenkins plug-in interface) - this is the biggest peace of work
Create and set up a new project in the jenkins interface (name, working directory, etc.)
Tell jenkins to use source code management (e.g. subversion module), enter the ClearCase repos to use, set the desired behavior of the source code management
Set a build trigger (I recommend checking the source code management each minute: * * * * *)
Add a build step and select "Build a Visual Studio project or solution using MSBuild" - this option should appear after installation of the MSBuild plugin (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin)
Set the path to the .sln file (you have checked it out from your repository)
Add more optional arguments if desired (eg /p:Configuration=Release or Debug or whatever http://msdn.microsoft.com/en-us/library/vstudio/ms164311%28v=vs.110%29.aspx)
Play around untill it works
Btw., I recommend to put all external dlls into your repository.

how to make installer (exe) file in windows

I have created a WPF application. I want to make installer file (exe) for this application.
This application also uses some other 3rd party files (bat files); which i have zipped.
I want to unzip this file while installing and set the path of unzipped dir in Path variable also.
I got a link http://www.msdotnet.co.in/2012/06/how-to-create-setup-fileexe-file-from.html#.U3GT7YGSzxp
which tells how to create a installer file.
How to achieve unzipped part and setting environment vairable while making installer?
Thanks
Take a look at wix from Microsoft.
It can be run standalone, but is great run from within visual studio. You write a small xml file detailing what you want installed, and it does the rest.
To run a zip command, use a CustomAction.
Search for Install-shield. It is old tool but having good scripting capability like what you are expecting (i.e) Unzipping the folder and dealing with path environment variable
Use Inno Setup (http://jrsoftware.org/isinfo.php) or NSIS (http://nsis.sourceforge.net/Main_Page).
Both are free (open source) installation systems with many possibilities and huge community around (even here on SO).
They are really easy to use (especially Inno) and they are powerful so it is easy to achieve your required functionality.
Take a look at Stall:
https://github.com/jamesqo/Stall
It's an OSS project that lets you install your app from the command line, no configuration required.
Example Usage:
stall path/to/YourApp -e YourApp.exe -i YourApp.exe
This installs your app straight to the user's computer without having to make an intermediary MSI.
If you have to unzip files as well, you may want to just consider a simple batch files that downloads the binaries + unzips the contents + runs Stall.

Windows Scripting: What and How to do this? Batch Files or Something else?

What I am trying to do is have some sort of script run in windows (ideally .cmd file/batch file) when double clicked it should create a short-cut menu in the start menu and set a path in the windows registry (i think thats what it is called) so that next time, for example, all I have to is get the variable JAVA_HOME to get the path I need.
What I need help in this is just examples on how to do these, what tutorials I should look at or even what key terms to search in Google (seriously) as I am very new to windows programming and what's used for what etc.
Thanks all
If you want to target all versions of Windows, your best choice is writing a MS-DOS Batch file (.bat). Here's a good tutorial that I've used in the past.
If you are targeting modern versions of Windows (Windows XP SP2/2003/Vista/7) you should definitely take a look at Windows PowerShell, which is the new standard automation engine for the Windows platform.PowerShell is a separate download for Windows XP SP2, Windows Server 2003 and Windows Vista, while it is included in Windows Server 2008 and Windows 7.
About Windows PowerShell
PowerShell is built on top of the .NET Framework and consists of a runtime environment, a scripting language and an interactive console.Here are some of its key features that I find most valuable:
All processing is done using CLR objects, instead of text as in traditional shells
It is possible to interact directly with the classes in the .NET Framework
It is possible to run commands written in any .NET language and distributed as DLLs (called Cmdlets)
Great collection of built-in commands to accomplish most administrative tasks
The scripting language's syntax is C-style (curly braces...)
The runtime can be hosted inside any managed process as an ad-hoc automation engine
This isn't of course a complete list of all the features in PowerShell. If you are interested, I recommend you to look into it. Here is a good place to start.

Resources