Help writing automated script!

Associate
Joined
16 May 2006
Posts
1,414
Location
Copenhagen
I've been asked to write a script that automatically downloads, installs and runs a .exe file.

My programming knowledge is very limited, but I know what I would like to happen and was hoping someone can point me in the right direction.

I want this to run on Windows, and make a check for 32/64 bit and then download the corresponding file from a URL. I assume an IF statement can handle this?

The application is in an Installer package, so was hoping I can run the install with a parameter that can handle it unattended "/qn" or "installer.exe --mode unattended" for example?

The last part of the installer then asks to run the program so should be handled by the above, correct?

I'd rather do this myself and understand each step than simply copying and pasting. Any help would be great!
 
Soldato
Joined
16 Jun 2013
Posts
5,381
Which version of windows?

It kinda depends on what the installer is set up to do. As far as I know theres no way to run an installer in silent/unattended mode unless the package has been built with that in mind.

Most malware handle this by default so its possible :D.

I think a use case might be appropriate to give a better answer.
 
Associate
OP
Joined
16 May 2006
Posts
1,414
Location
Copenhagen
Thanks for the replies so far, a friend mentioned I should look into Powershell instead? Thoughts?

Which version of windows?

It kinda depends on what the installer is set up to do. As far as I know theres no way to run an installer in silent/unattended mode unless the package has been built with that in mind.

I think a use case might be appropriate to give a better answer.

-Windows 10 32/64 bit
-Interesting point, how can a script handle this instead then?
-The case I have been given is to download an application, install and then run it. The application is for atomic modelling but I doubt that's relevant. Its more a test of how it can be done. Could be quick and simple or a bit more complex and more flexible...
 
Man of Honour
Joined
13 Oct 2006
Posts
90,824
Powershell is pretty powerful but I'm a bit old school and prefer a batch file :S

One of the most reliable ways of working out whether its 32 or 64 bit install is via querying WMI for the OSArchitecture information i.e. wmic OS get OSArchitecture (though it will take a little parsing) - you can check the environmental variable PROCESSOR_ARCHITECTURE but in rare cases it might return an unexpected string rather than the more normal x86 or AMD64 or you can check registry keys.
 
Soldato
Joined
16 Jun 2013
Posts
5,381
-Windows 10 32/64 bit
-Interesting point, how can a script handle this instead then?
-The case I have been given is to download an application, install and then run it. The application is for atomic modelling but I doubt that's relevant. Its more a test of how it can be done. Could be quick and simple or a bit more complex and more flexible...

Is the program free? Just wondering if it's possible for me to download it and have a look see if I can work it out. I'm guessing it's not though.

Sorry I meant a use case for how the script is intended on being used. Would you have the user download the script to start the install instead of the exe/msi, is it designed to be pushed out to a load of computers on a network.

Is the installer one your companies made? Just wondering if it would be possible to get the 32/64 versions combined into a single package.
 
Associate
OP
Joined
16 May 2006
Posts
1,414
Location
Copenhagen
The program is free, it's simply intended to be downloaded onto a single machine and then run to install and launch the program. Perhaps the script can also check if the program is already installed, but simply installing and launching would be great.

The program is here:
http://quantumwise.com/products/download (The red section with 'VNL')

The installer was configured in house, but I'm not able to change the configuration of that at the moment.

Thanks in advance!
 
Soldato
Joined
16 Jun 2013
Posts
5,381
Right I've tried the silent installation and unless there's a switch I'm missing it's just not set up to do it. I think there's a way around it but cant find it atm.

Right otherwise simplest way I can think of would be to do an if/else check on if program files(x86) folder exists if it does then you've got a 64 bit machine if not it's 32 bit. Will remove the occasionally random returns of wmic queries. AFAIK theres never going to be an instance where the program files (x86) doesn't exist on a 64bit version.
http://steve-jansen.github.io/guides/windows-batch-scripting/part-5-if-then-conditionals.html

From a quick read BITS used to be the way to download files from the commandline but its been deprecated and replaced with powershell(Invoke WebRequest).
http://stackoverflow.com/questions/4619088/windows-batch-file-file-download-from-a-url

If you have a word with whoever packaged the installer hopefully they can tell you if there are switches for silent installation.

Hopefully that helps?
 
Man of Honour
Joined
13 Oct 2006
Posts
90,824
Some programs create the missing program files folder anomalously which will throw off 64bit detection - the simplest reliable check is against the environment variable PROCESSOR_ARCHITECTURE the WMIC call should be the most reliable but does need extra parsing to get the 2nd line of text.
 
Soldato
Joined
16 Jun 2013
Posts
5,381
Some programs create the missing program files folder anomalously which will throw off 64bit detection - the simplest reliable check is against the environment variable PROCESSOR_ARCHITECTURE the WMIC call should be the most reliable but does need extra parsing to get the 2nd line of text.

Ahh I didn't know that. Thank you and apologies to OP.
 
Associate
OP
Joined
16 May 2006
Posts
1,414
Location
Copenhagen
Right I've tried the silent installation and unless there's a switch I'm missing it's just not set up to do it. I think there's a way around it but cant find it atm.

Using CMD and running the installer with "--help" it tells you which modes are enabled. Luckily "--mode unattended" was available and can be invoked in PowerShell.

Right otherwise simplest way I can think of would be to do an if/else check on if program files(x86) folder exists if it does then you've got a 64 bit machine if not it's 32 bit. Will remove the occasionally random returns of wmic queries. AFAIK theres never going to be an instance where the program files (x86) doesn't exist on a 64bit version.
http://steve-jansen.github.io/guides/windows-batch-scripting/part-5-if-then-conditionals.html

I used an If check on ([System.Environment]::Is64BitProcess) as I think it is more reliable than the folder check. The program installs to Program Files (x86) regardless of installer version (32/64 bit).

Thanks for the help to everyone so far! One last thing I'd like to add is downloading the files over HTTPS, but I'm running into an error:
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
 
Back
Top Bottom