分享

Sysinternals Suite系列工具——脚本更新工具包

 昵称11935121 2018-09-01

update script

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.'

$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后缀的脚本,利用管理员权限进行运行。

最后在定义为定时任务就可以设定每天检查获取更新。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多