LoginSignup
0
0

More than 1 year has passed since last update.

PowerShell なんちゃってクリックワンス(新旧比較なし)

Last updated at Posted at 2023-01-19

概要

今回クライアントからツール(VBA)をユーザーが意識せず常に最新版を実行したいとの要求があり、メールなどで展開ではなくWEBサーバー上のファイルを自動でダウンロードして実行する仕組みを考察

要件

①ユーザーは常に一つのファイルしか実行しない
②ツールに改修が入った場合でも配布することなく最新版が実行出来る
③VisualStudioなど使わずPowerShellで実現する

実装

①WEBディレクトリに対象ファイルを配置
②テキストファイルに以下コードを貼り付け.ps1で保存

ps1
#-- 多重起動防止
    if((Get-Process|Where-Object{$_.MainWindowTitle -like '*test.xlsm*'}).Count -gt 0)
    {
        Exit
    }

#-- Excelファイルをダウンロード
    Invoke-WebRequest -uri http://~/test.xlsm -outfile .\test.xlsm

#-- 終了遅延
  Start-Sleep -s 2

#-- Webのマークを削除する
  Get-ChildItem -Recurse -File | ?{
    $_ | Get-Item -Stream Zone.Identifier -ErrorAction Ignore;
  } | Remove-Item -Stream Zone.Identifier;

#-- VBA起動
try {
    $excel = New-Object -ComObject Excel.Application
    # 表示する・しない            
    $excel.Visible = $false
    # ブックを開く                                     
    $book = $excel.Workbooks.Open([string](Resolve-Path (Get-ChildItem "*.xlsm")))
}
finally {
    # プロセスを開放する
    $excel = $null
    [GC]::Collect()
Exit
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0