Sysinternals Suite系列工具介紹繼續
Sysinternals Suite是一個工具的集合,裡面有很多Windows相關的工具,如:Autoruns,Process Explorer,Bginfo等工具。但是這些工具經常性的更新,如果需要更新,還需要把整個工具包下載下來,並重新覆蓋,那麼如何自動更新 SysInternals 工具套件,其實我們可以用powershell腳本進行定時任務,每天進行自動檢查更新。腳本如下:
function Update-SysinternalsHTTP ($ToolsLocalDir = "c:\temp\sys")
{
if (Test-Path $ToolsLocalDir){
cd $ToolsLocalDir
$DebugPreference = "SilentlyContinue"
$wc = new-object System.Net.WebClient
$userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)"
$wc.Headers.Add("user-agent", $userAgent)
$ToolsUrl = "https://live.sysinternals.com"
$toolsBlock="
.*"$WebPageCulture = New-Object System.Globalization.CultureInfo("en-us")
$Tools = @{}
$ToolsPage = $wc.DownloadString($ToolsUrl)
$matches=[string] $ToolsPage |select-string -pattern "$ToolsBlock" -AllMatches
foreach($match in $matches.Matches) {
$txt = ( ($match.Value -replace "
", "`r`n") -replace "]*?>","")foreach($lines in $txt.Split("`r`n")){
$line=$lines|select-string -NotMatch -Pattern "To Parent|^$|
" if ($line -ne $null){
$date=(([string]$line).substring(0,38)).trimstart(" ") -replace " "," "
$file=([string]$line).substring(52,(([string]$line).length-52))
$Tools["$file"]= [datetime]::ParseExact($date,"f",$WebPageCulture)
}
}
}
$Tools.keys|
ForEach-Object {
$NeedUpdate=$false
if (Test-Path $_)
{
$SubtractSeconds = New-Object System.TimeSpan 0, 0, 0, ((dir $_).lastWriteTime).second, 0
$LocalFileDate= ( (dir $_).lastWriteTime ).Subtract( $SubtractSeconds )
$needupdate=(($tools[$_]).touniversaltime() -lt $LocalFileDate.touniversaltime())
} else {$NeedUpdate=$true}
if ( $NeedUpdate )
{
Try {
$wc.DownloadFile("$ToolsUrl/$_","$ToolsLocalDir\$_" )
$f=dir "$ToolsLocalDir\$_"
$f.lastWriteTime=($tools[$_])
"Updated $_"
}
catch { Write-debug "發生錯誤: $_" }
}
}
}
}
cls
"更新開始..."
Update-Sysinternalshttp -ToolsLocalDir "E:\soft\SysinternalsSuite"
"更新結束"
Update-Sysinternalshttp -ToolsLocalDir "此處為工具包的路徑",請自行更換。
然後把改腳本保存為ps1後綴的腳本,利用管理員權限進行運行。
最後在定義為定時任務就可以設定每天檢查獲取更新。
閱讀更多 心欲無痕 的文章