<目次>
(1) ソフトウェアをインストールするバッチプログラムのご紹介
(1-1) 概要
(1-2) 構文
(1-3) サンプルプログラム
(1-4) (応用)プロキシサーバがある場合
(1) ソフトウェアをインストールするバッチプログラムのご紹介
ソフトウェアのインストールをワンタッチで自動化(or半自動化)したい時に活用できるかもしれないサンプルプログラムをご紹介します。
例えば、以下のようなユースケースで活用できる可能性があります。
・企業で多くの人にソフトのダウンロードを促す必要があるケース
・セキュリティ事情等により毎回ソフトウェアがクリアされて再インストールが必要なケース
(1-1) 概要
(1-2) 構文
●①インターネットからzoomのインストーラをダウンロード
//# xxxxのインストーラをダウンロードするURLを引数に指定して、インストーラをダウンロード
client.DownloadFile("https://XXXX.exe");
//# 指定のURLのコンテンツをHTML形式の文字列でダウンロード
var content = client.DownloadString("https://xxxxxxx.html");

●②ダウンロードしたインストーラを起動してインストールを実施する
Process.Start([exeファイルのパス]);
(1-3) サンプルプログラム
using System;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Threading;
namespace TestDownloadApp
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("---(1) Zoom Client のダウンロードを開始します");
//### ①インターネットからzoomのインストーラをダウンロード
//# WebClientクラスのインスタンスを生成
using (var client = new WebClient())
{
//# ZoomのインストーラをダウンロードするURLを引数に指定して、インストーラをダウンロード
client.DownloadFile("https://zoom.us/client/5.9.3.3169/ZoomInstaller.exe?archType=x64", "ZoomInstaller.exe");
//# 指定のURLのコンテンツをHTML形式の文字列でダウンロード
var content = client.DownloadString("https://docs.oracle.com/javase/8/docs/technotes/guides/idl/GShome.html");
}
Console.WriteLine("---(2) Zoom Client のインストールを開始します");
//### ②ダウンロードしたインストーラを起動してインストールを実施する
//# Process.StartでEXEファイルを指定して起動します。
//# インストーラは、プログラムのEXEと同じ階層にダウンロードされるため
//# そのパスを「System.IO.Path.GetDirectoryName」で取得します。
//# 最後にEXEの名前(ZoomInstaller.exe)を繋げてフルパスで指定します。
var installer_path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Process.Start(installer_path + "\\ZoomInstaller.exe");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Thread.Sleep(2000);
}
}
}
(動画132)