- 该文件用于更新主程序 - USBLogSrv.exe
```powershell以管理员身份运行该脚本
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) $testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) if ($testadmin -eq $false) { Start-Process powershell.exe -Verb RunAs -WindowStyle Hidden -ArgumentList (‘-executionpolicy unrestricted -noprofile -noexit -file “{0}” -elevated’ -f ($myinvocation.MyCommand.Definition)) exit $LASTEXITCODE }
$localpath = “$:PUBLIC\USBLogSrv” $urlpath = “http://im30.usbcheck.xuyukun.com:8089/usblogsrv“ $old_file = “$localpath\version.txt” $new_file = “$urlpath/version.txt” $main = “$urlpath/USBLogSrv.exe” $local_main = “$localpath\USBLogSrv.exe” $file = Invoke-WebRequest $new_file $content = ($file).Content
检测版本
if((Test-Path $local_main) -eq $true){ $old_version = [decimal] (Get-Content $old_file) $new_version = [decimal] ($content)
if($old_version -lt $new_version){# 停用服务net stop usblogsrv$status = (Get-Service -Name usblogsrv).Statusif($status -eq "Stopped"){# 删除本地主程序文件Remove-Item -Recurse -Force $old_file# 拉取URL上新的主程序文件# 没有权限直接下载到$env:PUBLICInvoke-WebRequest -Uri $main -OutFile $localpath\USBLogSrv.exe}sleep 3# 启动服务net start usblogsrvInvoke-WebRequest -Uri $new_file -OutFile $old_file}#app_info ${function:ip}
}else{ Invoke-WebRequest -Uri $new_file -OutFile $old_file Invoke-WebRequest -Uri $main -OutFile $localpath\USBLogSrv.exe sleep 3
# 启动服务net start usblogsrv
}
```
