• 该文件用于更新主程序 - 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)

  1. if($old_version -lt $new_version){
  2. # 停用服务
  3. net stop usblogsrv
  4. $status = (Get-Service -Name usblogsrv).Status
  5. if($status -eq "Stopped"){
  6. # 删除本地主程序文件
  7. Remove-Item -Recurse -Force $old_file
  8. # 拉取URL上新的主程序文件
  9. # 没有权限直接下载到$env:PUBLIC
  10. Invoke-WebRequest -Uri $main -OutFile $localpath\USBLogSrv.exe
  11. }
  12. sleep 3
  13. # 启动服务
  14. net start usblogsrv
  15. Invoke-WebRequest -Uri $new_file -OutFile $old_file
  16. }
  17. #app_info ${function:ip}

}else{ Invoke-WebRequest -Uri $new_file -OutFile $old_file Invoke-WebRequest -Uri $main -OutFile $localpath\USBLogSrv.exe sleep 3

  1. # 启动服务
  2. net start usblogsrv

}

```